这是一个解决方案,以便在布局中的视图之间添加相同的空间: make same space between button in linearlayout
但是请说我们有很多项目,我们需要将它们放在HorizontalScrollView手机设备中。
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<LinearLayout
android:id="@+id/shareLinearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btnRequestAPrescriptionRefill"
android:layout_marginTop="10dp" >
<Button
android:id="@+id/btnFacebook"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/btn_facebook" />
<View
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1" />
...
</LinearLayout>
</HorizontalScrollView>
此解决方案适用于手机,但在我们屏幕尺寸较大的平板电脑中,按钮之间的相同空间无效。按钮只是粘在一起,没有我们创建的空间:
<View
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1" />
有没有解决方案?
答案 0 :(得分:1)
滚动视图会根据其内容视图(线性布局)调整其大小,但是当屏幕足够大时,您需要反过来,您希望内容视图使其大小适应滚动视图。这有点矛盾。
执行此操作的唯一方法是为minWidth
指定LinearLayout
属性。
android:minWidth="200dp"
这是一个痛苦的屁股,因为你可能需要在运行时设置它,或者有不同版本的XML用于不同的屏幕分辨率。
对于大屏幕分辨率,另一种方法可能是在没有scrollview的情况下提供不同的XML。