2016-07-22 12 views
0

私は4つのテーブル行の重みを1に設定しました。これは異なる画面サイズで非常にうまく動作します。それは自動的に縮小し、すべての画像を表示し、画面に合うでしょう。androidどのようにtablayoutの画面サイズに応じて画像ビューを自動縮小する?

しかし、私はTablayoutフラグメント内に配置する場合、コンテンツがすべて表示されません。あなたがスクリーンショットから見ることができるように。誰もが問題を知っていますか?どうも。

enter image description here

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
tools:context="com.example.template_tab.frag_two" 
android:orientation="vertical"> 

<TableRow 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img0" 
     android:src="@drawable/sample_0" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img1" 
     android:src="@drawable/sample_1" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img2" 
     android:src="@drawable/sample_2" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img3" 
     android:src="@drawable/sample_3" 
     android:layout_weight="1" /> 
</TableRow> 

<TableRow 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"> 
    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img4" 
     android:src="@drawable/sample_4" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="9dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img5" 
     android:src="@drawable/sample_5" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img6" 
     android:src="@drawable/sample_6" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img7" 
     android:src="@drawable/sample_7" 
     android:layout_weight="1" /> 

</TableRow> 

<TableRow 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"> 
    <ImageView 
     android:layout_width="9dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img8" 
     android:src="@drawable/sample_8" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="9dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img9" 
     android:src="@drawable/sample_9" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="9dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img10" 
     android:src="@drawable/sample_10" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="9dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img11" 
     android:src="@drawable/sample_11" 
     android:layout_weight="1" /> 

</TableRow> 

<TableRow 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/result" 
     android:src="@drawable/sample_0" 
     android:layout_weight="1" /> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:id="@+id/display_text" 
     android:text="1908, 1920, 1932, 1944, 1956, 1968, 1980, 1992, 2004, 2016, 2028, 2040, 2052, 2064" 
     android:layout_weight="1" /> 
</TableRow> 
</LinearLayout> 
+0

ポストレイアウト・ファイル – Sharj

+0

セット親ビューを追加しました。 plzはあなたもそれは同じように高さ – gosulove

+0

顔をしていますそれでも動作しません。効果は同じです.. – Sharj

答えて

1

あなたは本当にものTableRowをTableLayout内部で使用されることになっている、あなたのケースのためのTableRowは必要ありません。 match_parent代わりのwrap_content

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.template_tab.frag_two" 
android:orientation="vertical"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="horizontal"> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img0" 
     android:src="@drawable/sample_0" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img1" 
     android:src="@drawable/sample_1" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img2" 
     android:src="@drawable/sample_2" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img3" 
     android:src="@drawable/sample_3" 
     android:layout_weight="1" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="horizontal"> 
    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img4" 
     android:src="@drawable/sample_4" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="9dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img5" 
     android:src="@drawable/sample_5" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img6" 
     android:src="@drawable/sample_6" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img7" 
     android:src="@drawable/sample_7" 
     android:layout_weight="1" /> 

</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="horizontal"> 
    <ImageView 
     android:layout_width="9dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img8" 
     android:src="@drawable/sample_8" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="9dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img9" 
     android:src="@drawable/sample_9" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="9dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img10" 
     android:src="@drawable/sample_10" 
     android:layout_weight="1" /> 

    <ImageView 
     android:layout_width="9dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/img11" 
     android:src="@drawable/sample_11" 
     android:layout_weight="1" /> 

</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="horizontal"> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/result" 
     android:src="@drawable/sample_0" 
     android:layout_weight="1" /> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:id="@+id/display_text" 
     android:text="1908, 1920, 1932, 1944, 1956, 1968, 1980, 1992, 2004, 2016, 2028, 2040, 2052, 2064" 
     android:layout_weight="1" /> 
</LinearLayout> 
</LinearLayout> 
+0

thxそれでも動作しません。結果は同じ:( – gosulove

+0

他のソリューションです?私はそれをテスト – gosulove

+0

、それが正しい動作します。あなたのレイアウトはフラグメント内にある場合は、必ず高さは、それが通常のレイアウトではうまく機能 – Sharj

関連する問題