【发布时间】:2018-12-22 23:17:08
【问题描述】:
我正在尝试将ImageButton 和 TextView 并排放置在 LinearLayout 中,按钮垂直大到足以适合布局 - 希望这应该适合宽度。布局的其余部分应由文本视图占据。
目前,我的 xml 文件中有以下布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".08"
android:background="#004D79"
android:orientation="horizontal">
<ImageButton
android:id="@+id/helpButton"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:cropToPadding="false"
android:layout_margin="3dp"
android:adjustViewBounds="true"
android:background="@drawable/help" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#000000"
android:text="Some placeholder text"
android:textColor="#ffffff"
/>
</LinearLayout>
此布局占用了 8% 的垂直空间。按钮的图像为 500x500。
但是,我遇到了一些问题!
当我以“原样”上面的布局运行时,imagebutton 是正确的高度,但它占据了布局的整个宽度;根本没有文本视图 - 所以看起来android:adjustViewBounds="true" 不起作用。
但是,如果我用android:src="@drawable/help" 替换android:background="@drawable/help",我会在布局的左侧得到一个小正方形区域,但上面没有图像。文本视图位于“按钮”的右侧,但它不覆盖布局的其余部分;它被包裹起来,以便它足够大以包含占位符文本。
我必须在我的应用程序中以编程方式调整按钮和文本视图的大小,例如 OnMapReady(...)?
编辑:我刚刚验证了图像文件在 res/drawable/help.png 中 - 但是为什么它应该出现在背景中(大小错误)但没有 src(大小正确) ) 对我来说是个谜。
【问题讨论】:
标签: android android-linearlayout imagebutton