[英]stretch imagebuttons in linearlayout to use available space
I've been playing with some XML in order to achieve the following; 为了达到以下目的,我一直在研究一些XML。
first row is a banner (works fine). 第一行是横幅(效果很好)。 Then; 然后; I have 3 buttons on each row. 我每行有3个按钮。 I want the buttons to take up all horizontal space (so; screen width diveded by 3). 我希望按钮占用所有水平空间(因此;屏幕宽度减3)。 Also, the images on the buttons should resize to that width, without changing aspect ratio!. 另外,按钮上的图像应调整为该宽度,而无需更改长宽比!。 How can this be done? 如何才能做到这一点?
Next; 下一个; if I add rows of ImageButtons, how should I 'shell' the LinearLayouts in a scrollview to maintain the width distribution for 3 buttons? 如果我添加ImageButtons的行,应该如何在滚动视图中“封装” LinearLayouts以维护3个按钮的宽度分布?
thnx n
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:orientation="vertical" >
<ImageView
android:id="@+id/blogbanner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@drawable/test_banner_ad" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="@drawable/trololo" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:scaleType="matrix"
android:src="@drawable/scout" />
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitEnd"
android:src="@drawable/painting" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<ImageButton
android:id="@+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/whoop" />
<ImageButton
android:id="@+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/drown" />
<ImageButton
android:id="@+id/imageButton6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/love" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<ImageButton
android:id="@+id/imageButton7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/shredder" />
<ImageButton
android:id="@+id/imageButton8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/frog" />
<ImageButton
android:id="@+id/imageButton9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/yeah03" />
</LinearLayout>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.