【问题标题】:How to fill ImageButton edges equally with the LinearLayout in Android如何在 Android 中使用 LinearLayout 平均填充 ImageButton 边缘
【发布时间】:2013-07-12 09:58:44
【问题描述】:

我有两个 LinearLayout。我在第一个 LinearLayout 中设置了 ImageButton。如何用 LinearLayout 平均填充 imagebutton 边缘,接下来如何用ImageButton 平均填充背景图像边缘??

例如。 如果我的 LinearLayout 的尺寸高度为:20 dp 宽度:20dp,那么 imagebutton 的尺寸应为高度:20 dp 宽度:20dp,而背景图像的尺寸应为高度:20 dp 宽度:20dp。

我的代码:

    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:showDividers="none" >

    <LinearLayout
        android:id="@+id/zdj"
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:layout_weight="0.25"
        android:orientation="vertical"

        >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:scaleType="fitCenter"
            android:src="@drawable/wawel" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:layout_weight="0.75"
        android:background="@drawable/tlo12"
        android:orientation="horizontal"
        android:paddingLeft="@dimen/activity_horizontal_margin">

    <TextView
        android:id="@+id/textViewNazwaObiektu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1.63"
        android:textSize="20sp" />

    </LinearLayout>


</TableRow>

【问题讨论】:

    标签: android android-linearlayout imagebutton


    【解决方案1】:

    如果你使用

            android:scaleType="fitCenter"
    

    您的图像不会填满整个图像视图

    如果您不关心图像方面,请使用:

            android:scaleType="fitXY"
    

    【讨论】:

    • 值得指出的是ImageView默认的scaleType是fitCenter,而Button的默认是fitXY。不过,不确定 ImageButton。
    • 我已将 android:scaleType="fitCenter" 更改为 android:scaleType="fitXY" 但还是一样;/
    • 尝试将 ImageButton 的背景设置为 null "android:background="@null" 这将删除按钮背景,此背景在其图像中包含填充。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-15
    • 2018-10-14
    • 1970-01-01
    • 2021-07-20
    • 2013-03-26
    • 1970-01-01
    相关资源
    最近更新 更多