ViewFlipper布局问题

时间:2012-12-08 13:49:01

标签: android android-layout viewflipper

我已经定义了一个这样的视图翻转器:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:tools="http://schemas.android.com/tools"
        android:orientation="horizontal" android:layout_width="match_parent"
        android:layout_height="match_parent" android:layout_marginRight="5dp"
        xmlns:android="http://schemas.android.com/apk/res/android">

        <TextView android:id="@+id/Heading001" android:gravity="center"
            android:layout_width="105dp" android:layout_height="40dp"
            android:layout_marginLeft="10dp" android:layout_marginRight="20dp"
            android:layout_marginTop="5dp" android:text="XXX" android:textSize="25sp"
            android:background="@drawable/rectanglefield" android:textAppearance="?android:attr/textAppearanceMedium" />


        <TextView android:id="@+id/tvLongName" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_alignParentBottom="false"
            android:layout_alignParentTop="true" android:layout_marginTop="0dp"
            android:gravity="center" android:layout_toRightOf="@+id/Heading001"
            android:text="XXX" android:textAppearance="?android:attr/textAppearanceMedium"
            android:typeface="normal" />

        <TextView android:id="@+id/tvUsage" android:layout_below="@+id/tvLongName"
            android:layout_toRightOf="@id/Heading001" android:layout_height="wrap_content"
            android:layout_width="wrap_content" android:layout_marginRight="5dp"
            android:textColor="#ff0000" android:text="R"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView android:id="@+id/tvCardinality"
            android:layout_height="wrap_content" android:layout_width="50dp"
            android:layout_alignParentRight="false" android:layout_below="@+id/tvLongName"
            android:layout_toRightOf="@+id/tvUsage" android:layout_marginRight="5dp"
            android:text="(0..1)" android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView android:id="@+id/tvDatatype" android:gravity="center_vertical"
            android:layout_width="wrap_content" android:layout_height="40dp"
            android:layout_marginLeft="10dp" android:layout_marginRight="15dp"
            android:layout_marginTop="5dp" android:layout_alignParentRight="true"
            android:text="XX" android:textColor="#000000" android:background="@drawable/rectanglewhite"
            android:textSize="25dp" android:textAppearance="?android:attr/textAppearanceMedium" />

        <ViewFlipper android:id="@+id/viewFlipper1"
            android:layout_width="fill_parent" android:layout_height="fill_parent"
            android:layout_alignRight="@+id/Heading001" android:layout_weight="1"
            android:layout_marginRight="50dp">
            <include android:id="@+id/flipperView02" android:layout_width="wrap_content"
                layout="@layout/detail_item_view02" />
            <include android:id="@+id/flipperView01" android:layout_width="wrap_content"
                layout="@layout/detail_item_view01" />
        </ViewFlipper>
    </RelativeLayout>

然后将flipperView01视图定义如下:

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

    <TextView android:id="@+id/tvNotes"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="55dp" 
        android:text="abcdef ef abcdef abcdef " 
        android:textAppearance="?android:attr/textAppearanceMedium"/>

</LinearLayout>

我遇到的问题是我希望“flipperView01”中的TextView是对话框的全宽,目前它不是很窄的

enter image description here

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

要解决此问题,请从android:layout_alignRight="@+id/Heading001"移除ViewFlipper属性,因为这会将ViewFlipper的右边距与 Heading001 {{1}对齐}右边距(TextView的尺寸有限)。

关于你的布局:

  • TextViewlayout_weight
  • 中无效
  • 您应该仅在布局中第一次出现该ID时使用RelativeLayout表示法,在您使用@+id/theId的下一个地方,您只需使用id