【问题标题】:Android RelativeLayout probAndroid 相对布局问题
【发布时间】:2012-11-19 11:53:01
【问题描述】:

我想创建如下布局。

为此,我使用了代码。如果textWoundTypeDetails 文字很小,则可以,但如果文字很大,则会将图像推离屏幕,并且文字会填满总宽度。

<TextView
        android:id="@+id/textWoundType"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:padding="5dp"
        android:text="@string/wound_screener" />

<ImageView
        android:id="@+id/closebtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:layout_alignParentRight="true"
        android:src="@drawable/buttonclose" />
<ImageView
        android:id="@+id/imgWoundType"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/textWoundTypeDetails"
        android:layout_below="@id/textWoundType"
        android:src="@drawable/article_noimg" />

<TextView
        android:id="@+id/textWoundTypeDetails"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@id/textWoundType"
        android:padding="5dp"
        android:text="A wound caused by superficial damage to the skin, no deeper than the epidermis. It is less severe than a laceration, and bleeding, if present, is minimal." />

如何解决这个问题?

【问题讨论】:

  • 上述布局也可以使用Linearlayout
  • imageView 必须使用 linearLayout

标签: android android-relativelayout right-to-left


【解决方案1】:

试试下面的代码。希望对你有所帮助。

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="2" >

        <TextView
            android:id="@+id/textWoundType"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_gravity="left"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="SCRAPES" />

        <ImageView
            android:id="@+id/closebtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_weight="1"
            android:padding="5dp"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="2" >

        <ImageView
            android:id="@+id/imgWoundType"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:padding="5dp"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textWoundTypeDetails"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="A wound caused by superficial damage to the skin, no deeper than the epidermis. It is less severe than a laceration, and bleeding, if present, is minimal." />
    </LinearLayout>

</LinearLayout>

【讨论】:

    猜你喜欢
    • 2012-02-17
    • 1970-01-01
    • 2011-03-18
    • 2013-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多