android子布局没有显示

时间:2013-06-29 20:57:55

标签: android android-layout android-linearlayout relativelayout

我有一个内部有三个RelativeLayout的LinearLayout。前两个孩子的布局显示。第三个没有显示。当我将子项从RelativeLayout更改为LinearLayouts时,第三个仍未显示。有想法该怎么解决这个吗?未显示的那个包含ImageView。

以下是代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:clickable="true"
    android:orientation="horizontal" >

    <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@drawable/back1" >

            <View
                android:id="@+id/fract"
                android:layout_width="60dp"
                android:layout_height="1dp"
                android:layout_centerInParent="true"
                android:background="#00a5e5"
                android:paddingLeft="5dp"
                android:paddingRight="5dp" />

            <TextView
                android:id="@+id/nume"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@id/fract"
                android:layout_centerHorizontal="true"
                android:ellipsize="end"
                android:singleLine="true"
                android:text="58 apple"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textSize="14sp" />

            <TextView
                android:id="@+id/denom"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/fract"
                android:layout_centerHorizontal="true"
                android:ellipsize="end"
                android:singleLine="true"
                android:text="46 orange"
                android:textSize="12sp"
                android:textStyle="bold" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@drawable/back2" >

            <TextView
                android:id="@+id/red_1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:ellipsize="end"
                android:singleLine="true"
                android:text="11 apple "
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textSize="14sp" />

            <TextView
                android:id="@+id/red_2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/red_1"
                android:layout_centerHorizontal="true"
                android:layout_marginRight="5dp"
                android:ellipsize="end"
                android:singleLine="true"
                android:text="13 oranges "
                android:textSize="12sp"
                android:textStyle="bold" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#ffffff" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:src="@drawable/guess" />
        </RelativeLayout>
</LinearLayout>

3 个答案:

答案 0 :(得分:1)

您的第二个相对布局的高度为

android:layout_height="match_parent"

尝试放:

android:layout_height="wrap_content"

- 编辑 - 尝试添加权重属性。      

</RelativeLayout>

<RelativeLayout
android:weight=1
>

</RelativeLayout>

<RelativeLayout
android:weight=1>

</RelativeLayout>

答案 1 :(得分:1)

android:layout_centerInParent="true"从视图中删除它,如果你想添加一个你可以单独从RelativeLayout中添加的视图,你的Layout已经在父的中心了,为了调试目的,设置每个的宽度查看到某个级别,以便您可以看到。您的两个RelativeLayout已经占据了线性布局的宽度,因此第三个布局没有剩余空间。

答案 2 :(得分:1)

我决定以编程方式进行。我使用context.getResources().getDisplayMetrics().widthPixels获取设备的宽度。然后从那里我逐个像素地布置我的棋子,可以这么说。

相关问题