生活随笔
收集整理的這篇文章主要介紹了
TabHost.TabSpec中的标签实现图文左右排(默认上下排)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
TabHost.TabSpec
代碼如下:
?
Xml代碼??
<?xml?version="1.0"?encoding="utf-8"?>?? <FrameLayout?android:id="@+id/settingTab"?? ????xmlns:android="http://schemas.android.com/apk/res/android"?? ????android:layout_width="fill_parent"?android:layout_height="fill_parent">?? ????<LinearLayout?android:id="@+id/scheduleSetting"?android:layout_width="fill_parent"?android:layout_height="fill_parent">?? ????????<TextView?android:id="@+id/tv01"?android:layout_width="wrap_content"?? ????????????android:layout_height="wrap_content"?android:text="@string/setting_schedule"?/>?? ????</LinearLayout>?? ?? ????<LinearLayout?android:id="@+id/taskSetting"?android:layout_width="fill_parent"?android:layout_height="fill_parent">?? ????????<TextView?android:id="@+id/tv02"?android:layout_width="wrap_content"?? ????????????android:layout_height="wrap_content"?android:textSize="24dip"?? ????????????android:text="@string/setting_task"?/>?? ????</LinearLayout>?? </FrameLayout>??
?
?
Activity:
Java代碼??
public?class?SettingActivity?extends?TabActivity?{?? ????private?TabHost?tab?=?null;?? ?? ????@Override?? ????public?void?onCreate(Bundle?savedInstanceState)?{?? ????????super.onCreate(savedInstanceState);?? ?? ????????tab?=?this.getTabHost();?? ????????LayoutInflater.from(this).inflate(R.layout.setting,?? ????????????????tab.getTabContentView(),?true);?? ?? ????????tab.addTab(tab.newTabSpec("schedulTab").setIndicator(?? ????????????????getString(R.string.setting_schedule),?? ????????????????this.getResources().getDrawable(R.drawable.calendar))?? ????????????????.setContent(R.id.scheduleSetting));?? ????????tab.addTab(tab.newTabSpec("taskTab").setIndicator(?? ????????????????getString(R.string.setting_task),?? ????????????????this.getResources().getDrawable(R.drawable.settings))?? ????????????????.setContent(R.id.taskSetting));?? ?? ?????????? ????????TabWidget?tabWidget?=?tab.getTabWidget();?? ????????for?(int?i?=?0;?i?<?tabWidget.getChildCount();?i++)?{?? ????????????TextView?tv?=?(TextView)?tabWidget.getChildAt(i).findViewById(?? ????????????????????android.R.id.title);?? ????????????ImageView?iv?=?(ImageView)?tabWidget.getChildAt(i).findViewById(?? ????????????????????android.R.id.icon);?? ????????????iv.setPadding(10,?0,?0,?0);?? ????????????tv.setPadding(50,?0,?0,?0);?? ?????????????? ?? ????????????RelativeLayout.LayoutParams?paramsLeft?=?new?RelativeLayout.LayoutParams(?? ????????????????????RelativeLayout.LayoutParams.WRAP_CONTENT,?? ????????????????????RelativeLayout.LayoutParams.WRAP_CONTENT);?? ????????????paramsLeft.addRule(RelativeLayout.ALIGN_RIGHT);?? ????????????paramsLeft.addRule(RelativeLayout.CENTER_VERTICAL,?RelativeLayout.TRUE);?? ????????????iv.setLayoutParams(paramsLeft);?? ?????????????? ????????????RelativeLayout.LayoutParams?paramsRight?=?new?RelativeLayout.LayoutParams(?? ????????????????????RelativeLayout.LayoutParams.WRAP_CONTENT,?? ????????????????????RelativeLayout.LayoutParams.WRAP_CONTENT);?? ????????????paramsRight.addRule(RelativeLayout.ALIGN_RIGHT);?? ????????????paramsRight.addRule(RelativeLayout.CENTER_VERTICAL,?RelativeLayout.TRUE);?? ????????????tv.setLayoutParams(paramsRight);?? ????????????tv.setTextColor(Color.BLACK);?? ????????}?? ????}?? }??
?
效果如下圖:
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀
總結
以上是生活随笔為你收集整理的TabHost.TabSpec中的标签实现图文左右排(默认上下排)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。