我正在创建一个 Android 应用程序,并尝试在图片和一些文本下方添加三个选项卡。
______________________________
| _____________ |
| | | text |
| | picture | text |
| | | text |
| ————————————— |
| _______ ________ _______ |
| | tab | | tab | | tab | |
| ———————————————————————— |
| | | |
| | | |
| | content | |
| | here | |
| | | |
| | | |
| |
——————————————————————————————
我不知 Prop 体怎么做。 任何想法将不胜感激。 谢谢。
最佳答案
<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>
这应该为您提供基本结构,然后在您的 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 源代码示例取自 http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
您可能需要调整 XML 中每个组件的 layout_width、layout_height,我没有测试该布局。
关于java - 在 android 中,如何将选项卡放在顶部包含图像的 View 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6389909/