簡體   English   中英

在linearlayout中拉伸圖像按鈕以使用可用空間

[英]stretch imagebuttons in linearlayout to use available space

為了達到以下目的,我一直在研究一些XML。

第一行是橫幅(效果很好)。 然后; 我每行有3個按鈕。 我希望按鈕占用所有水平空間(因此;屏幕寬度減3)。 另外,按鈕上的圖像應調整為該寬度,而無需更改長寬比!。 如何才能做到這一點?

下一個; 如果我添加ImageButtons的行,應該如何在滾動視圖中“封裝” LinearLayouts以維護3個按鈕的寬度分布?

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>

將每行的3個按鈕放入另一個水平布局,然后使用“ weight ”屬性定義其寬度。

圖像需要具有“ fill_parent”尺寸並使用scaleXY

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM