2012-09-02 40 views
8

ライブラリ互換性を使用してGridLayoutを使用する際に問題があります。 android:layout_gravity="fill_horizontal"の代わりにapp:layout_gravity="fill_horizontal"を使用していますが、TextView内のすべてのコンテンツは表示されません。すべてを表示するには、TextView「タイトル」の高さを設定する必要がありますが、高さを設定するのではなく、動的な高さが必要です。GridLayout内のTextViewの動的な高さ

答えて

27

TextViewにはlayout_width="0dp"layout_gravity="fill_horizontal"を設定する必要があります。

<TextView 
android:layout_width="0dp" 
app:layout_gravity="fill_horizontal" /> 

してください、ここでは完全な例を参照してください。https://groups.google.com/d/msg/android-developers/OmH3VBwesOQ/ZOGR0SGvC3cJかここに:GridLayout内部TextViewを使用してhttp://daniel-codes.blogspot.com/2012/01/gridlayout-view-clipping-issues.html

+0

** app:** layout_gravityに注意することが重要です。私はスタイルの価値を設定していたとリントは私に警告していない、問題を把握するために私をしばらくかかった。 – basilisk

+0

2行目にある場合は、前の行の幅の幅をとります –

17

には問題があるが、は一緒に両方を使用するための良い方法あります。

これは、例えばレイアウトは次のようになります。

TextView inside GridLayout

そして、これは完全なレイアウトxmlです、重要な行は***でマークされています。

<?xml version="1.0" encoding="utf-8"?> 
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:columnCount="3"    * this example uses 3 columns 
    android:orientation="horizontal" > *** use "horizontal" 

<TextView        * just a normal view 
    android:layout_column="0" 
    android:layout_row="0" 
    android:background="#666666" 
    android:text="A" 
    android:textColor="#afafaf" 
    android:textSize="60sp" 
    android:textStyle="bold" /> 

<TextView        * this text will not be cut! 
    android:layout_width="0dp"   *** important: set width to 0dp 
    android:layout_height="wrap_content" 
    android:layout_column="1" 
    android:layout_columnSpan="2"  * colspan does also work with this 
    android:layout_gravity="fill_horizontal|bottom"  *** set to "fill*"! 
    android:layout_row="0" 
    android:text="This view has 2 columns. Lorem ipsum dolor sit amet, consetetur sadipscing elitr." 
    android:textColor="#666666" /> 

</GridLayout> 

必要に応じて、またこの組み合わせは動作します:あなたが仕事に、このためにandroid以外の任意の名前空間を使用する必要はありません

android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:layout_gravity="fill" 
    android:gravity="bottom" 

注意を。

+0

ありがとう、それは動作します。しかし、私はあなたがそのトリックをどのように発見したのか不思議です。 (0dpの 'layout_width'と' layout_gravity'のためのfillプロパティ) – Leo

+2

素晴らしい仕事が見つかりました。私のTextLayoutが私のGridLayoutの中にテキストを正しくラッピングするのは苦労しました。この同じ問題に関する多くのトピックに関する他のすべての提案と回答に続きましたが、自分だけが働いていました。どうもありがとうございました! :) –