0

ウェイトを使用してレスポンスレイアウトを作成しようとしていますが、この場合はスクロールビューも使用する必要があります。ウェイトとスクロール表示の線形レイアウト

これは、この時点で私のコードです:

<RelativeLayout 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=".EncyclopediaFragment"> 

    <!--Linear Container--> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:weightSum="100"> 

     <!--Title Box--> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="20" 
      android:orientation="horizontal" 
      android:weightSum="100"> 

      <!--Empty Space--> 
      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="5"> 


      </LinearLayout> 

      <!--Text Box--> 
      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="95"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:text="@string/encyclopedia_mosntersLabel" 
        android:gravity="center" 
        android:textAlignment="viewStart"/> 

      </LinearLayout> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="40"> 

     </LinearLayout> 

    </LinearLayout> 

が、それはthisようにする必要があります。

レイアウトはウェイトに反応すると思われますが、同時にスクロールすることが可能にする必要があります。

私の質問は次のとおりです。ウェイトに応じてレイアウトを作成すると同時に、画像のようにスクロールできるレイアウトを作成するにはどうすればよいですか?

+0

どのように多くのモンスターのとどのように多くのタワーの?私はグループとしての意味ですか?それはモンスターの1つのグループとタワーの1つのグループですか? – OBX

+0

スクロールビュー内にレイアウトを配置するだけで済みます。以前はまったく同じ目的のために、グリッドレイアウトとリニアレイアウトの両方をウェイトで使用していました。 – ArchiFloyd

+0

ここに部分的なヒントがあります。あなたのモンスターが横断するためには、テーブル行(幅=マッチ親、重心=中央)、各モンスター(幅= 0dp、重さ= 1).....を推薦します。 – seekingStillness

答えて

1

あなたは6匹のモンスターと8タワーズの決定された数を持っている場合は、ここでは、あなたのレイアウトを整理する方法です。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Monsters"/> 

      <!-- the following LinearLayout should be repeated twice for 6 Monsters --> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal"> 

       <MonsterView 
        android:layout_weight="1" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" /> 

       <MonsterView 
        android:layout_weight="1" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" /> 

       <MonsterView 
        android:layout_weight="1" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" /> 

      </LinearLayout> 

      ... 


      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Towers"/>   

      <!-- the following LinearLayout should be repeated twice for 6 Towers --> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal"> 

       <TowerView 
        android:layout_weight="1" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" /> 

       <TowerView 
        android:layout_weight="1" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" /> 

       <TowerView 
        android:layout_weight="1" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" /> 

      </LinearLayout> 

      ... 


      <!-- attention here for two Towers in the last row -->   

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:weightSum="3"> 

       <TowerView 
        android:layout_weight="1" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" /> 

       <TowerView 
        android:layout_weight="1" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" /> 

      </LinearLayout> 

     </LinearLayout> 
    </ScrollView> 
+0

いいえ、それは動作しますが、どのように応答可能な方法で各TowerViewまたはMonsterViewの高さを変更できますか? –

+0

'Dimension name =" monster_height "> 20dp'の値に数値リソースを定義し、 'MonsterView'タグの中で参照することができます:' android:layout_height = "@dimen/monster_height" ' – foxanna

+0

ウェイトを使用する方法はありませんか? –

0
<RelativeLayout 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=".EncyclopediaFragment"> 

<!--Toolbar--> 
<ScrollView 
android:layout_width="match_parent" 
android:layout_height="wrap_content"> 

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<!--Linear Container With Weights--> 

</RelativeLayout> 
</ScrollLayout> 
</RelativeLayout> 
+0

これは役に立たない。外側の 'RelativeLayout'は何もしません。そして、 'ScrollView'内のレイアウトは' android:layout_height = "wrap_content" 'を持つべきです。それ以外の場合は意味がありません! – foxanna

0

あなたScrollView内のコンテンツはwrap_parentを使用する必要があり、そしてあなたはそれがandroid:fillViewport="true"をセット内のコンテンツを伸ばしたい場合。これを試してみてください:

<RelativeLayout 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=".EncyclopediaFragment"> 

    <ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

     <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

      <!--Linear Container--> 

     </RelativeLayout> 
    </ScrollLayout> 
</RelativeLayout> 
関連する問題