我想拥有图像视图的网格类型布局。开始我试图看看我是否可以使用简单的按钮来获得这个。 这很容易,我可以使用线性布局创建一组按钮,但是当我尝试使用imageView而不是按钮时出现问题。
有没有一种简单的方法来强制android以适合imageView在一个按钮适合的完全相同的空间。
图像视图似乎忽略宽度的重量?我不介意图片的高宽比是否会变形,但理想情况下,它会保持这个比例,只是缩小图像直到其完全吻合。什么是最好的方式来得到这个工作?试图获取排列在网格类型布局中的图像视图
这是我当前XML .......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="4" >
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/chicken" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
</LinearLayout>
尝试为您的ImageView使用android:scaleType =“fitXY”。 –