当我创建一个布局时,我添加一个imageview,然后添加两个按钮。 它在5英寸屏幕上看起来不错,但是在3.2英寸中,底部的按钮没有正确显示。按钮的一半在屏幕外。
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_marginLeft="10.0dip"
android:layout_marginTop="20.0dip"
android:layout_marginRight="10.0dip"
style="@style/TextPrincipal"
android:text="@string/ferits_activity"/>
<View android:id="@+id/separator"
android:background="#8a9597"
android:layout_width = "fill_parent"
android:layout_height="2dip"
android:layout_centerVertical ="true"
android:layout_alignParentTop="true"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
>
<ImageView
android:layout_width="50dip"
android:layout_height="30dip"
android:src="@drawable/esquerra"
android:layout_weight="1"
android:layout_gravity="center_vertical"
/>
<ImageView
android:id="@+id/FeritsImatge"
android:layout_width="300dip"
android:layout_height="240dip"
android:contentDescription="@string/ferits_activity"
android:layout_marginRight="20dip"
android:src="@drawable/esta_ferida"
android:layout_weight="1"
android:layout_gravity="center_vertical"
/>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40.0dip"
android:layout_marginRight="40.0dip"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
style="@style/AppTheme">
<Button android:id="@+id/BotoSiFerits"
android:background="#ffabd128"
android:clickable="true"
android:layout_width="fill_parent"
android:layout_height="50.0dip"
android:layout_marginTop="10.0dip"
android:text="@string/resposta_si"
android:textColor="@color/blanc"
style="@style/AppTheme"
android:onClick="passarMoure"/>
<Button android:id="@+id/BotoNoFerits"
android:background="#ffabd128"
android:clickable="true"
android:layout_width="fill_parent"
android:layout_height="50.0dip"
android:layout_marginTop="10.0dip"
android:text="@string/resposta_no"
android:layout_below="@id/BotoSiFerits"
android:textColor="@color/blanc"
style="@style/AppTheme"
android:onClick="passarEsperar" />
</RelativeLayout>
</LinearLayout>
答案 0 :(得分:2)
当您有太多内容无法放入屏幕时,您有两个常规选项:
ScrollView
,以便用户可以在内容较小的情况下滚动内容。我建议使用选项2,因为它可以在设备之间提供更一致的体验。
你的布局应该看起来像这样:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Your existing LinearLayout with the height set to wrap_content -->
</ScrollView>