【问题标题】:Background Image Overflows in Tabs选项卡中的背景图像溢出
【发布时间】:2012-12-07 20:21:19
【问题描述】:

我正在开发一个使用 2 TabActivity 控件的应用程序。当我设置它覆盖全屏的任何选项卡的背景图像时,它甚至覆盖选项卡控件。但是选项卡控件保留在图像的后面。这真是奇怪的行为。请任何人帮助我。

这是我的主选项卡控件的代码:\

<?xml version="1.0" encoding="utf-8"?>
<TabHost
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@android:id/tabhost"
   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>

下面是添加背景标签的代码:

Tab1:

public class FirstTab extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    /* First Tab Content */
    TextView textView  =(TextView) findViewById(R.id.textview);
    textView.setText("First Tab");
}

}

ma​​in.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" 
      android:background="@drawable/lux">

<TextView
    android:id="@+id/textview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />

</LinearLayout>

勒克斯图像全屏显示...我希望它显示在标签下。任何帮助表示赞赏。

【问题讨论】:

  • 背景是 9-patch png 吗?
  • 那么我建议使用 9-patch 图像,因为它会缩放以适应容器。

标签: android android-layout tabs android-tabhost


【解决方案1】:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" 
      android:background="@drawable/lux">

看到你有 layoutSet 高度和宽度填充父级,使其 wrap_content 并保持 lux 图像尺寸非常小以适合选项卡,或者将 dp 中的高度和宽度设置为 48dp/64dp/72dp/96dp

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    • 1970-01-01
    相关资源
    最近更新 更多