2017-10-17 8 views
1

すべてのアンドロイドデバイス用にデザインを作成したいと思います。このために、私はLinearLayoutsを高さで使用し、それとパーセンテージのソリューションを使用します。LinearLayoutはweightプロパティ(高さ)を使用してTextViewテキストを切り捨てます

画面は、多くのセクション(重さのあるLinearLayouts)で分割されています。これらのLinearLayoutsには、TextViewのような要素があります。

しかし、高さのあるLinearLayoutを使用すると、下部のTextViewを切り取ることができます。

重みに基づいて動的にテキストサイズを変更するにはどうすればよいですか?

コード:

<LinearLayout 
    android:layout_height="0dp" 
    android:layout_width="match_parent" 
    android:layout_weight="0.04" 
    android:weightSum="1"> 
    <LinearLayout 
     android:layout_height="match_parent" 
     android:layout_width="0dp" 
     android:layout_weight="0.05799" /> 
    <LinearLayout 
     android:layout_height="match_parent" 
     android:layout_width="0dp" 
     android:layout_weight="0.86951"> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left" 
      android:text="Benachrichtigungen" 
      android:textStyle="bold" 
      android:textSize="20sp" 
      android:id="@+id/header"/> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_height="match_parent" 
     android:layout_width="0dp" 
     android:layout_weight="0.0722106" /> 
</LinearLayout> 

画像:

Image

+1

あなたの現在のxmlは、これがより速く答えるのを助けるかもしれません。 –

+0

私は自分の質問を更新しました。提案ありがとう。 :) –

+0

あなたの高さを制限する必要がありますか? LinearLayoutの高さをwrap_contentに設定しないと、多分、 –

答えて

1

私はプログラム的に私の問題を解決することができます:

このコードは私のフラグメントでOnCreateView方法です。 TextViewの高さに基づいてテキストサイズを生成します。

view.ViewTreeObserver.GlobalLayout += (sender, e) => 
{ 
    var headerTextView = view.FindViewById<TextView>(Resource.Id.header); 
    var headerTextViewHeightInSp = PxToSp(view.Context, headerTextView.Height); 

    headerTextView.SetTextSize(ComplexUnitType.Sp, headerTextViewHeightInSp - 5); // 5 is a offset (space between outter borderline and text) 
}; 
関連する問題