简体   繁体   English

在android中,如何将标签页放在顶部包含图片的视图中?

[英]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.

相关问题 如何将制表符不在布局的顶部? - How can I put tabs NOT at the top of the layout? 如何下载图像并将其放入 Android 的视图中 - How can I download and put an image in a view in Android 如何把一个Android视图(工具提示)放在另一个内部视图之上? - how to put an android view (tooltip) on top of another inner view? 如何将 listView 放在 android 工作室的滚动视图中? - How can I put a listView inside a scroll view on android studio? Android-如何将不同的图像资源放入SimpleAdapter? - Android - How I can put different Image resources to the SimpleAdapter? 当我在应用浏览器中的android webview中打开链接时,如何在左上方放置关闭按钮 - when i open a link in android webview in app browser how can i put close button on top left 如何正确将图像放置在具有指定高度的ImageView的顶部? - How can I correctly put an image at the top of an ImageView having a specified height? 如何将JLabel和JTextField置于Image之上? - How Do I Put JLabel and JTextField on top of Image? Android图片查看顶部裁剪 - Android image view top crop 我如何将JButton放在图像上? - how can i put a JButton on an image?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM