![](/img/trans.png)
[英]selecting an Image from Grid and displaying it in Gallery View in android application
[英]Android view for displaying a image gallery
我正在尝试建立一个显示一组图像的视图,该图像被1或2列划分。 因此,列数及其宽度都可能变化。
我已经看过现有的视图,但是不能满足我的要求。
它是否已经存在,或者哪个当前现有的android视图更适合实现以下布局:
绿色多边形是(可单击的)图像。
我目前正在尝试使用包含不同TableRows的TableLayout,具体取决于行。 但是,恐怕此解决方案无法有效处理大量图像。
一个TableLayout就足够了,并且可以在许多设备上很好地扩展。 但是,请记住,TableLayout不可滚动,因此,如果您希望它可滚动(我建议您在用户的屏幕分辨率很低的情况下使用它),则用..等来掩盖表格。下面是您可以使用的骨架。 它由3行和2列组成。 第一行和第二行与图片的比例为50/50,最后一行在图片上包含整行。.使用layout_weight进行播放,以使它们包含更多空间。 将layout_weight 2放在该行的第一个图像上,并在第二个图像上放置1,将为第一个图像分配更多空间。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:layout_weight="1">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:layout_margin="10dp"
>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageButton
android:contentDescription="@string/starting_content_lessions"
android:id="YourId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="YourLocation"
android:background="YourBackground"
android:layout_weight="1" /> <!-- Puting this on both items in the row makes it stretch the whole lenth -->
<ImageButton
android:contentDescription="xxx"
android:id="xxxx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="xxx"
android:background="@drawable/custom_button"
android:layout_weight="1" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:contentDescription="xxxx"
android:id="xxx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="xxx"
android:background="@drawable/custom_button"
android:layout_weight="1" />
<ImageButton
android:id="xxx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="xxx"
android:contentDescription="xxx"
android:src="xxx"
android:layout_weight="1" />
</TableRow>
<TableRow>
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="xxx" />
</TableRow>
</TableLayout>
</ScrollView>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.