0

我想在屏幕顶部和屏幕底部显示一些按钮的图像。我写了这段代码,但图像没有显示!我怎么解决这个问题?如果我将图像转换为相对布局之外,图像显示页面顶部,但视图显示就像我分离了首页的底部页面。为什么?

按钮的另一个问题。btn4 按钮显示在另一个按钮之上?为什么?

<?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/background">

<RelativeLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="0"
    android:layout_gravity="bottom">
     <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/smallyelowbar"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:layout_alignParentTop="true"/>
        <FrameLayout
            android:id="@+id/frameLayout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="@drawable/background" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true">
        <Button android:id="@+id/btn1"
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:background="@drawable/more_selector"/>
        <Button 
            android:id="@+id/btn2"
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:background="@drawable/contact_selector"/>
        <Button android:id="@+id/btn3"
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:background="@drawable/product_selector"/>
        <Button android:id="@+id/btn4"
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:background="@drawable/introduce_selector"/>
        </LinearLayout>
</RelativeLayout>
</LinearLayout>
4

4 回答 4

0

在我看来,您的 FrameLayout 将 ImageView 隐藏在其后面。尝试将 FrameLayout 放在 ImageView 下方(通过在其上设置 android:below= 属性,或将 ImageView 放在 xml 中的 FrameLayout 上)。

于 2013-09-25T07:26:55.290 回答
0

你可以试试这个。

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

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/bottom" >

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:adjustViewBounds="true"
            android:background="#495663"
            android:scaleType="fitXY" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/bottom"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btn1"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#DBEAF9" />

        <Button
            android:id="@+id/btn2"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#DBEAF9" />

        <Button
            android:id="@+id/btn3"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#DBEAF9" />

        <Button
            android:id="@+id/btn4"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#DBEAF9" />
    </RelativeLayout>

</RelativeLayout>

工作完美。快乐编码!

于 2013-09-25T07:34:18.397 回答
0

试试这个 XML

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

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/relative_btngroup"
        android:background="@drawable/ic_launcher" >

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:adjustViewBounds="true"
            android:scaleType="fitXY" />

        <FrameLayout
            android:id="@+id/frameLayout"
            android:layout_width="fill_parent"
            android:layout_height="match_parent" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relative_btngroup"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <Button
            android:id="@+id/btn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <Button
            android:id="@+id/btn2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/btn1" />

        <Button
            android:id="@+id/btn3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/btn2" />

        <Button
            android:id="@+id/btn4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/btn3" />
    </RelativeLayout>

</RelativeLayout>
于 2013-09-25T08:01:30.047 回答
0

这里的问题是您的 frameLayout 与您的图像视图重叠......这就是为什么当您将其移出相对布局时它可以工作的原因。

试试下面的代码

<?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/background">

<RelativeLayout 
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0"
android:layout_gravity="bottom">
    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="@drawable/background" />
 <ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/smallyelowbar"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    android:layout_alignParentTop="true"/>


<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_alignParentBottom="true">
    <Button android:id="@+id/btn1"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:background="@drawable/more_selector"/>
    <Button 
        android:id="@+id/btn2"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:background="@drawable/contact_selector"/>
    <Button android:id="@+id/btn3"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:background="@drawable/product_selector"/>
    <Button android:id="@+id/btn4"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:background="@drawable/introduce_selector"/>
    </LinearLayout>
</RelativeLayout>
</LinearLayout>
于 2013-09-25T08:08:04.020 回答