我有这个代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/shape"
android:gravity="top" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@null"
android:onClick="btnCat1"
android:src="@drawable/ic_launcher" >
</ImageButton>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageButton1"
android:layout_centerInParent="true"
android:clickable="false"
android:text="@string/hello_world" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@null"
android:onClick="btnCat1"
android:src="@drawable/ic_launcher" >
</ImageButton>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageButton1"
android:layout_centerInParent="true"
android:clickable="false"
android:text="@string/hello_world" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@null"
android:onClick="btnCat1"
android:src="@drawable/ic_launcher" >
</ImageButton>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageButton1"
android:layout_centerInParent="true"
android:clickable="false"
android:text="@string/hello_world" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@null"
android:onClick="btnCat1"
android:src="@drawable/ic_launcher" >
</ImageButton>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageButton1"
android:layout_centerInParent="true"
android:clickable="false"
android:text="@string/hello_world" />
</RelativeLayout>
</LinearLayout>
图像和文本有4组,但是如果我以小分辨率打开它,则只能看到3个框。如何设置它们以显示在下一行?
编辑:它应该看起来像这个例子
看来您可能正在尝试复制GridView的行为。您可以使用GridView根据视图的大小完成从2列到4列的切换。
根据您的目标版本,另一种可能适合您的替代方法是:指定可用的屏幕空间较少时要使用的其他布局文件(请检查表2“ smallestWidth”行):提供替代资源。您可以通过指定一个文件夹(例如“ res / layout-sw600dp /”)并将相同名称的布局文件放入该文件夹中来使用此方法。在每个布局文件中,然后使用所需的列数显式布局文件。
如果您定位的设备无法识别“ sw”资源修饰符,则可以在代码中手动模拟此操作,方法是指定一个布局文件以按名称进行充气,然后根据屏幕尺寸选择一个更大或更小的一个(在应用运行时当然可以使用)。
让我知道您是否想详细说明一种特定的方法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句