2016-04-26 84 views
0

我的布局如下,如果我删除android:weightSum="3"然后一切正常,但如果我在的LinearLayout把android:weightSum="3"(所以每个TextView的具有1/3宽度的屏幕),则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,但你的孩子为什么要使用weigthsum = 3时,要将它划分至6份超限3 –

+0

变化weightsum 3至6 –

+0

?要么给机器人:layout_weight =” 5或给weigthsum = 6到您的线性布局 –

回答

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”'设置好的,在horizo​​ntalscrollview不能滚动? –

+0

@TigerWang,需要修复显示宽度,因为水平滚动视图没有X限制 –

0

王虎王,

我也在寻找解决方案。

我想用Horizo​​ntalScrollView和具有相同大小的10个按钮,但一次显示5点相等大小的按钮,而无需使用WRAP_CONTENT所有按钮。

对于按钮,我想指定layout_weight,weightSum和layout_width = “0dp”。

让我知道你是否找到解决方案。

感谢, 阿肖克

+0

对不起,我也没有解决方案。 –

相关问题