是否可以让 android:drawableLeft 填充按钮视图上的父项?
Is it possible to make android:drawableLeft fill the parent on a Button View?
所以我在 xml 中定义了一个简单的 Button
,如下所示:
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_margin="5dp"
android:gravity="center"
android:text="@string/home_button_student"
android:textSize="@dimen/abc_text_size_headline_material"
android:onClick="buttonClick"
android:id="@+id/home_button_student"
android:drawableLeft="@drawable/ic_action_emo_cool"/>
我在 LinearLayout
中有几个这样的东西,正如预期的那样,它们填满了屏幕,每个占据了相同数量的 space,每个看起来都类似于:http://i.imgur.com/fMNldop.jpg
我在这里遇到的问题是,您可以看到可绘制对象的高度仅与文本相同,我想知道是否有办法使可绘制对象的比例与按钮本身的高度相同如果不使用像使用另一个 LinearLayout
创建我自己的按钮这样的解决方法,我想坚持使用 Button
.
我的 res 文件夹中的正确文件夹(xxhdpi、xhdpi 等)中有不同版本的图像,但它似乎只想使用最小的图像。
编辑:这似乎是因为提供的图像太小了,正如我在上面所说的那样,我有各种尺寸的图像,我怎么能告诉 android 使用大屏幕上的大屏幕而不是默认的小屏幕?我认为这就是拥有多种尺寸的全部意义所在。
为此,您需要像这样
将 layout_height 从 fill_parent 更改为 wrap_content
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:text="@string/home_button_student"
android:textSize="@dimen/abc_text_size_headline_material"
android:onClick="buttonClick"
android:id="@+id/home_button_student"
android:drawableLeft="@drawable/ic_action_emo_cool"/>
如果你想要一个非常大的按钮,那么确保你有一个等高的 drawable image.and 而且这里不需要给重量,
drawable 将只有位图的大小。提供大图就好了。
您可以使用您的自定义布局,如可向左或向右绘制,无论您想要什么,只需使用放置在此图像视图中的线性布局和视图按钮。所以你可以放你想要的图片
所以我在 xml 中定义了一个简单的 Button
,如下所示:
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_margin="5dp"
android:gravity="center"
android:text="@string/home_button_student"
android:textSize="@dimen/abc_text_size_headline_material"
android:onClick="buttonClick"
android:id="@+id/home_button_student"
android:drawableLeft="@drawable/ic_action_emo_cool"/>
我在 LinearLayout
中有几个这样的东西,正如预期的那样,它们填满了屏幕,每个占据了相同数量的 space,每个看起来都类似于:http://i.imgur.com/fMNldop.jpg
我在这里遇到的问题是,您可以看到可绘制对象的高度仅与文本相同,我想知道是否有办法使可绘制对象的比例与按钮本身的高度相同如果不使用像使用另一个 LinearLayout
创建我自己的按钮这样的解决方法,我想坚持使用 Button
.
我的 res 文件夹中的正确文件夹(xxhdpi、xhdpi 等)中有不同版本的图像,但它似乎只想使用最小的图像。
编辑:这似乎是因为提供的图像太小了,正如我在上面所说的那样,我有各种尺寸的图像,我怎么能告诉 android 使用大屏幕上的大屏幕而不是默认的小屏幕?我认为这就是拥有多种尺寸的全部意义所在。
为此,您需要像这样
将 layout_height 从 fill_parent 更改为 wrap_content<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:text="@string/home_button_student"
android:textSize="@dimen/abc_text_size_headline_material"
android:onClick="buttonClick"
android:id="@+id/home_button_student"
android:drawableLeft="@drawable/ic_action_emo_cool"/>
如果你想要一个非常大的按钮,那么确保你有一个等高的 drawable image.and 而且这里不需要给重量,
drawable 将只有位图的大小。提供大图就好了。
您可以使用您的自定义布局,如可向左或向右绘制,无论您想要什么,只需使用放置在此图像视图中的线性布局和视图按钮。所以你可以放你想要的图片