2016-04-26 11 views
0

私のレイアウトは、android:weightSum="3"を削除しても問題ありませんが、android:weightSum="3"をLinearLayoutに入れれば、Horizo​​ntalScrollViewはスクロールできないように見えます。 THXHorizo​​ntalScrollViewはandroid:weightSumで動作しませんか?

<HorizontalScrollView 
      android:id="@+id/bottom_bar_id" 
      android:layout_width="match_parent" 
      android:layout_height="40dp" 
      android:fillViewport="true" 
      android:scrollbars="none"> 

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

       <TextView 
        android:id="@+id/oneMonth" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:layout_marginLeft="15dp" 
        android:layout_marginRight="15dp" 
        android:textColor="@color/text_title" 
        android:text="one"/> 


       <TextView 
        android:id="@+id/threeMonth" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:layout_marginLeft="15dp" 
        android:layout_marginRight="15dp" 
        android:textColor="@color/text_title" 
        android:text="two"/> 

       <TextView 
        android:id="@+id/halfYear" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:layout_marginLeft="15dp" 
        android:layout_marginRight="15dp" 
        android:textColor="@color/text_title" 
        android:text="three"/> 

       <TextView 
        android:id="@+id/oneYear" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:layout_marginLeft="15dp" 
        android:layout_marginRight="15dp" 
        android:textColor="@color/text_title" 
        android:text="four"/> 


       <TextView 
        android:id="@+id/thisYear" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:layout_marginLeft="15dp" 
        android:layout_marginRight="15dp" 
        android:textColor="@color/text_title" 
        android:text="five"/> 

       <TextView 
        android:id="@+id/beginNow" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:layout_marginLeft="15dp" 
        android:layout_marginRight="15dp" 
        android:textColor="@color/text_title" 
        android:text="six"/> 
      </LinearLayout> 
     </HorizontalScrollView> 
+1

あなたがweigthsum 3を与えたが、あなたの子供はあなたが6部にそれを分割しているのに、なぜあなたはweigthsum = 3を使用している6 –

+0

変更weightsum 3を超えていますか? android:layout_weight = "。5を与えるか、リニアレイアウトにweigthsum = 6を与えてください。 –

+0

に制限3 –

答えて

0

私はこの方法でそれをやった:

DisplayMetrics metrics = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(metrics); 
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(metrics.widthPixels/YourChildWeight, LinearLayout.LayoutParams.MATCH_PARENT); 
parentView.addView(childView, params); 

あなたがChildWeightを与える必要があります。

希望すると、これが役立ちます。

+0

しかし、なぜアンドロイド:weightSum =" 3 "' setted、Horizo​​ntalscrollviewスクロール? –

+0

@TigerWang、横幅のスクロールビューにXの制限がないため、表示幅を修正する必要があります。 –

0

タイガーワン、

私はこの解決策も探しています。

Horizo​​ntalScrollViewを使用し、同じサイズのボタンが10個ありますが、すべてのボタンでwrap_contentを使用せずに一度に5個の等しいサイズのボタンを表示したいと考えています。

ボタンの場合、layout_weight、weightSum、layout_width = "0dp"を指定します。

解決策が見つかったら教えてください。

おかげで、 アショク

+0

申し訳ありませんが、解決策はありません。 –

関連する問題