0

親が右に配置されているボタンの左側に TextView を配置する RelativeLayout があります。そのため、TextView に表示するテキストが wrap_Content 以上に増えると、Button に重なってしまいます。そのため、超過したテキストを次の行に表示するソリューションが必要です。この問題を解決するのを手伝ってくれる人はいますか?
以下のレイアウトでは、TextView2 の Text が "1111111111111111111111" の場合、 TextView1 とオーバーラップします。それを防ぐ方法は?
私のレイアウトは以下の通りです:

    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_margin="10dp"
    android:scaleType="fitXY"
    android:src="@drawable/icon" >
    </ImageView>

     <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
      android:layout_height="wrap_content"
    android:layout_alignTop="@+id/imageView1"
    android:layout_margin="5dp"
    android:text="TextView"
    android:textSize="22dp" 
    android:layout_toRightOf="@id/imageView1"
    >
        </TextView>

 <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:focusable="false"
    android:text="Button" 
    android:layout_alignTop="@+id/imageView1"

    >
</Button> 

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@id/button1"
    android:text="TextView222"
    android:textSize="22dp"
    android:layout_margin="5dp"
    android:layout_alignTop="@+id/imageView1"
    android:ellipsize="end"
    >
</TextView>


上記のレイアウトでは、TextView2 の Text が "1111111111111111111111" の場合、 TextView1 とオーバーラップします。それを防ぐ方法

4

2 に答える 2

2

android:layout_toLeftOf="@+id/button"Button と衝突しないように TextView に追加するだけです。

次のようになります。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/button"
        android:text="11111111111111111111111111111111111111111111111111111111111111111111111111111111111"/>

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Potatoe"/>

</RelativeLayout>

あなたは質問を変更しました...しかし、私はこの新しい質問にも答えます。1 つの行に詰め込もうとしている可能性があります。ただし、レイアウトを水平 LinearLayout に変更し、いくつかのlayout_weight属性を使用してみましょう。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:scaleType="fitXY"
        android:src="@drawable/ic_launcher"/>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:text="111111111111111111111111111111111"
        android:textSize="22dp"/>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:ellipsize="end"
        android:text="222222222222222222222222222222222"
        android:textSize="22dp"/>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:text="Button"/>

</LinearLayout>

注:属性textView2を使用したため、新しい行に折り返されません。ellipse幸運を!

于 2012-09-06T19:53:12.623 に答える