[英]In android, how can I put tabs in a view containing an image on top?
I am creating an android application and am trying to add three tabs underneath a picture and some text. 我正在创建一个android应用程序,并试图在图片和一些文本下方添加三个标签。
______________________________
| _____________ |
| | | text |
| | picture | text |
| | | text |
| ————————————— |
| _______ ________ _______ |
| | tab | | tab | | tab | |
| ———————————————————————— |
| | | |
| | | |
| | content | |
| | here | |
| | | |
| | | |
| |
——————————————————————————————
I do not know exactly how to accomplish this. 我不确切地知道如何做到这一点。 Any ideas would be greatly appreciated.
任何想法将不胜感激。 Thank you.
谢谢。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="image_source/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@android:id/text1"
android:text="some text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@android:id/text2"
android:text="some text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@android:id/text3"
android:text="some text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<TabHost
android:id="@+id/my_tab_viewer"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
</LinearLayout>
That should provide you the base structure, then add your tabs with in your activity: 这应该为您提供基本结构,然后在您的活动中添加标签:
TabHost tabHost = (TabHost) findViewById(R.id.my_tab_viewer);
TabHost.TabSpec spec = tabHost.newTabSpec("artists").setIndicator("Artists",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
Java source example taken from http://developer.android.com/resources/tutorials/views/hello-tabwidget.html Java源示例摘自http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
You may need to tweak the layout_width, layout_height for each component in the XML, I did not test that layout. 您可能需要调整XML中每个组件的layout_width,layout_height,但我没有测试该布局。
Sounds like the Android TabHost widget is what you're looking for, in a standard Activity subclass (Android's TabActivity is probably too inflexible for the layout you're proposing). 听起来好像您正在寻找Android TabHost小部件,它在标准Activity子类中(Android的TabActivity对于您建议的布局可能太不灵活了)。
TabHost is a widget that provides a tab bar, with a FrameLayout to display the contents for each tab. TabHost是一个小部件,提供一个选项卡栏,以及一个FrameLayout来显示每个选项卡的内容。 You can put it underneath the picture/text in your layout using either a RelativeLayout (preferred) or LinearLayout.
您可以使用RelativeLayout(首选)或LinearLayout将其放在布局中的图片/文本下方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.