java - 在 android 中,如何将选项卡放在顶部包含图像的 View 中?

标签 java android android-layout tabs android-tabhost

我正在创建一个 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/

相关文章:

java - struts2 - 具有单独操作类的多个提交按钮

android - 如何在 SurfaceView 中旋转视频 *.mp4?

java - 设置多方向 - Android

java - 鼠标 clickAndHold() 在使用 Selenium Webdriver 的 Firefox 上无法正常工作

java - CalenderView 不存在 - 试图实现 DatePickerDialog

java - Arraylist<ABC> 中的索引与其他 Arraylist 进行比较

android - 检查事件是否已经在日历中

java - Android Studio//导入语句错误//未使用导入语句

android - ImageView 作为网络图像的掩码或参数 - 如何?

android - Android上的 "Recycleview"和 "Listview"有什么区别?