在Android中,我怎样才能把标签含有顶部图像的看法? [英] In android, how can I put tabs in a view containing an image on top?
问题描述
我创建一个Android应用程序,我试图添加三个选项卡一张照片和一些文字下方。
______________________________
| _____________ |
| | |文|
| |图片|文|
| | |文|
| ------------- |
| _______ ________ _______ |
| |标签| |标签| |标签| |
| ------------------------ |
| | | |
| | | |
| |内容| |
| |这里| |
| | | |
| | | |
| |
------------------------------
我不知道究竟如何做到这一点。
任何想法将大大AP preciated。
谢谢你。
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT>
<的LinearLayout
机器人:方向=横向
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT>
< ImageView的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:SRC =image_source />
<的LinearLayout
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<的TextView
机器人:ID =@机器人:ID / text1中
机器人:文本=一些文本
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT/>
<的TextView
机器人:ID =@机器人:ID /文本2
机器人:文本=一些文本
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT/>
<的TextView
机器人:ID =@机器人:ID /文字3
机器人:文本=一些文本
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT/>
< / LinearLayout中>
< / LinearLayout中>
< TabHost
机器人:ID =@ + ID / my_tab_viewer
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<的LinearLayout
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:填充=5DP>
< TabWidget
机器人:ID =@机器人:ID /标签
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT/>
<的FrameLayout
机器人:ID =@机器人:ID / tabcontent
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:填充=5DP/>
< / LinearLayout中>
< / TabHost>
< / LinearLayout中>
这应该为您提供了基础结构,然后在您的活动添加标签:
TabHost tabHost =(TabHost)findViewById(R.id.my_tab_viewer);
TabHost.TabSpec规格= tabHost.newTabSpec(艺术家)。setIndicator(艺术家
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(意向);
tabHost.addTab(规范);
http://developer.android.com拍摄Java源的例子/resources/tutorials/views/hello-tabwidget.html
您可能需要调整layout_width,layout_height每个组件的XML,我没有测试布局。
I am creating an android application and am trying to add three tabs underneath a picture and some text.
______________________________
| _____________ |
| | | 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
You may need to tweak the layout_width, layout_height for each component in the XML, I did not test that layout.
这篇关于在Android中,我怎样才能把标签含有顶部图像的看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!