2013-05-27 102 views
0

下面xml中的日期TextView在屏幕右側被切斷。我怎樣才能解決這個問題?在屏幕右側切斷Android TextView

另外我不確定如果我是這樣做的權利,但加密和簽名ImageViews將永遠不會同時出現在一起,它會是或。

<LinearLayout 
       android:id="@+id/date_container" 
       android:layout_width="80dip" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:layout_marginTop="@dimen/date_margin_top" 
       android:orientation="horizontal" 
       > 
       <ImageView 
        android:id="@+id/encrypted" 
        android:layout_width="36dip" 
        android:layout_height="16dip" 
        android:layout_gravity="top" 
        android:src="@drawable/badge_encrypted" /> 
       <ImageView 
        android:id="@+id/signed" 
        android:layout_width="36dip" 
        android:layout_height="16dip" 
        android:layout_gravity="top" 
        android:src="@drawable/badge_signed" /> 
       <ImageView 
        android:id="@+id/paperclip" 
        android:layout_width="36dip" 
        android:layout_height="16 dip" 
        android:layout_gravity="top" 
        android:src="@drawable/ic_badge_attachment" /> 
       <TextView 
        android:id="@+id/date" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textSize="@dimen/date_font_size" 
        android:text="@string/long_string" 
        android:lines="1" /> 
      </LinearLayout> 

回答

0

,而不是設定固定的寬度,可以設置寬度match_parent並添加Layout_weight:

 <LinearLayout 
      android:id="@+id/date_container" 
      android:layout_width="80dip" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_marginTop="@dimen/date_margin_top" 
      android:orientation="horizontal" 
      > 
      <ImageView 
       android:id="@+id/encrypted" 
       android:layout_width="match_parent" 
       android:layout_weight="1" 
       android:layout_height="16dip" 
       android:layout_gravity="top" 
       android:src="@drawable/badge_encrypted" /> 
      <ImageView 
       android:id="@+id/signed" 
       android:layout_width="match_parent" 
       android:layout_height="16dip" 
       android:layout_weight="1" 
       android:layout_gravity="top" 
       android:src="@drawable/badge_signed" /> 
      <ImageView 
       android:id="@+id/paperclip" 
       android:layout_width="match_parent" 
       android:layout_height="16dip" 
       android:layout_weight="1" 
       android:layout_gravity="top" 
       android:src="@drawable/ic_badge_attachment" /> 
      <TextView 
       android:id="@+id/date" 
       android:layout_width="match_parent" 
       android:layout_weight="1" 
       android:layout_height="wrap_content" 
       android:textSize="@dimen/date_font_size" 
       android:text="@string/long_string" 
       android:lines="1" /> 
     </LinearLayout> 

但是這取決於你想要的。 Usualy,你必須爲多屏幕支持定義不同的佈局資源。在這個例子中,您還必須爲每個imageView設置scaleType,以正確的方式縮放每個資源。