In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article Xiaobian for you to introduce in detail "how to achieve a timeline effect in Android", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to achieve a timeline effect in Android" can help you solve your doubts.
In fact, it's just layout + dynamic production TextView. FrameLayout was selected at first, but later found a problem when dealing with click events, such as:
FrameLayout frameLayout= (FrameLayout) findViewById (R.id.frameLayout); for (...) {frameLayout.add (tv1); frameLayout.add (tv2); / / it is certainly not possible to deal with click events directly here. Tv1 and tv2 are coincident} FrameLayout frameLayout= (FrameLayout) findViewById (R.id.frameLayout); for (...) {tv1.setLayoutparams (....) FrameLayout.add (tv1); frameLayout.add (tv2); / / just deal with the click event here. I don't know why? }
So, directly change to Linearlayout, after changing to Linearlayout, the location of those TextView is also much easier to set. Here is the code:
Package com.lliq.ui; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.TextView; import com.lliq.R Public class HistoryActivity extends Activity {private final int space_year = 5; private final int space_month = 5; private String [] year = {"2010", "2011", "2012", "2013"} Private String [] [] month = {{"01", "03", "04", "11"}, {"07"}, {"01", "03", "04", "11"}, {"07"}}; boolean menu_falg = false / / Click the change menu icon private TextView [] tv_year; private TextView [] tv_month; private TextView content; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); requestWindowFeature (Window.FEATURE_NO_TITLE); setContentView (R.layout.iq_history) InitLayout ();} private void initLayout () {LinearLayout btnback = (LinearLayout) findViewById (R.id.history_layouthome); final TextView btnhome = (TextView) findViewById (R.id.history_btnhome) Btnback.setOnClickListener (new OnClickListener () {@ Override public void onClick (View arg0) {menu_falg =! menu_falg; btnhome.setBackgroundResource (menu_falg? R.drawable.menuspread: R.drawable.menu_n); MainActivity.handler.sendEmptyMessage (0);}}); content = (TextView) findViewById (R.id.content); LinearLayout timelayout = (LinearLayout) findViewById (R.id.timelayout); tv_year = new TextView [year.length] For (int I = 0; I < year.length; iyears +) {tv_ yearbook [I] = new TextView (this); tv_ yearbook [I] .setPadding (10, I = = 0? Space_year: space_year * (13-Integer.parseInt (Mont [I-1] [month [I-1] .length-1]), 0,0); tv_ yearbook [I] .getPaint () .setFakeBoldText (true); tv_ yearbook [I] .setTextSize (14); tv_ yearbook [I] .setTag (yearI]) Tv_ yearbook [I] .setText (yearbook [I] + "-"); tv_ yearbook [I] .setOnClickListener (new TimeLineClickListener (tv_ yearbook [I]); timelayout.addView (tv_ yearbook [I]); tv_month = new TextView [year.length]; for (int j = 0; j < month [I] .length) This +) {tv_ month [I] = new TextView (this); if (j = = 0) {tv_ month.setPadding (20, space_month * Integer.parseInt (Monthi [j]), 0,0) } else {tv_ [I] .setPadding (20, space_month * (Integer.parseInt (Month [I] [j])-Integer.parseInt (Month [I] [j-1])), 0,0) } tv_ [I] .setTextSize (12); tv_ Month.setText (Month[ I] [j] + "month -"); tv_ Month.setTag (yearI + "-" + month [I] [j])) Tv_ Month.setOnClickListener (new TimeLineClickListener (tv_ MonthListener); timelayout.addView (tv_ MonthListener) } class TimeLineClickListener implements OnClickListener {TimeLineClickListener (View v) {} @ Override public void onClick (View v) { Content.setText (v.getTag () .toString ()) } after reading this, the article "how to achieve a timeline effect in Android" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it yourself. If you want to know more about related articles, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.