2011-12-09 4 views
0
<RelativeLayout 
     android:id="@+id/RelativeLayout1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="5dp" > 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:adjustViewBounds="true" 
      android:src="@drawable/icon" /> 

     <TextView 
      android:id="@+id/fullnameTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@id/wayimageView" 
      android:textColor="@color/list_text_color" 
      android:textSize="16dp" 
      android:singleLine="false" 
      /> 
    <ImageView 
      android:id="@+id/imageView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="10dp" 
      android:adjustViewBounds="true" 
      android:src="@drawable/icon" /> 
    </RelativeLayout> 

私はImageViewの右側に名前を設定したいです。問題ありませんが問題は1つあります。名前が長すぎると、2番目の画像ビューの下に表示されます。 charsのサイズが10のときにtextViewの行の最大文字数(たとえば10)を与える方法はありますか?自動的に2行目に移動します。のTextViewライン - アドバイスは

答えて

3

2番目の画像の左側にあるように名前を設定するのが一番簡単な方法です。

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_marginLeft="10dp" 
    android:adjustViewBounds="true" 
    android:src="@drawable/icon" /> 

<ImageView 
    android:id="@+id/imageView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentright="true" 
    android:layout_marginRight="10dp" 
    android:adjustViewBounds="true" 
    android:src="@drawable/icon" /> 

<TextView 
    android:id="@+id/fullnameTextView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toLeftOf="@+id/imageView2" 
    android:layout_toRightOf="[email protected]/wayimageView" 
    android:textColor="@color/list_text_color" 
    android:textSize="16dp" /> 

0

あなたのTextViewの最大幅バインドすることができます:layout_width = "XDP" とアンドロイド:アンドロイドのようなのTextViewの大きさを与える

android:maxWidth="10dp"

0

をmaxLines = "2"または任意の値を指定します。あなたのテキストは、その後のTextViewの幅の外に出た場合は

0

あなたはドットが最後に追加されます「...」この

android:ellipsize="end" 
    android:maxLines="1" 
    android:scrollHorizontally="true" 

を利用することができます。

上記のコードが機能しない場合は、addroid:singleLine = "true"