2017-07-01 14 views
0

5つの画像ビューを1つずつ横に並べて、各画像ビューの幅を画面の1/5にする必要があります。代わりに、アクティビティ内の幅を測定し、設定するので、私はリニアレイアウトをこのように使用して結果を達成:Android five horizo​​ntal imageviews

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

     <com.davidbalas.brawlstarsinfo.CustomTextView 
      android:id="@+id/nameTextView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:textColor="@android:color/white" 
      android:textSize="28sp" 
      android:textStyle="bold" 
      app:fontName="supercell.ttf" /> 


     <com.davidbalas.brawlstarsinfo.CustomTextView 
      android:id="@+id/textView1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textColor="@android:color/white" 
      android:textSize="12sp" 
      android:textStyle="bold" 
      app:fontName="supercell.ttf" /> 

     <com.davidbalas.brawlstarsinfo.CustomTextView 
      android:id="@+id/top5" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:text="@string/top_5_brawlers_for" 
      android:textColor="@android:color/white" 
      android:textSize="22sp" 
      android:textStyle="bold" 
      app:fontName="supercell.ttf" /> 

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

      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:contentDescription="@string/top_5_brawlers_for" 
       android:src="@drawable/barley" /> 

      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:contentDescription="@string/top_5_brawlers_for" 
       android:src="@drawable/barley" /> 

      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:contentDescription="@string/top_5_brawlers_for" 
       android:src="@drawable/barley" /> 

      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:contentDescription="@string/top_5_brawlers_for" 
       android:src="@drawable/barley" /> 

      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:contentDescription="@string/top_5_brawlers_for" 
       android:src="@drawable/barley" /> 

     </LinearLayout> 

    </LinearLayout> 

しかし、私は、ネストされた重みは、パフォーマンスのために悪いですエラーが発生します。私が探しているものを達成するために、良い、他の方法は何ですか?

+0

多分constrait-layout –

+1

このリンクを参照してください。あなたは理解するでしょう[https://stackoverflow.com/questions/19636323/nested-weights-are-bad-for-performance-in-my-xml-code](https://stackoverflow.com/questions/19636323/) – Suresh

+0

はい、無視して、その警告を無視して、あなたのレイアウトにweight_sumを使用することができます –

答えて

0

この方法でこの問題を解決します。

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

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


</LinearLayout> 


</LinearLayout> 
関連する問題