Image 是否使用LinearLayout将图像和按钮设置为相同高度?
我使用的是带有weightSum的LinearLayout,因此我可以设计通用屏幕,以在所有屏幕大小上运行。可能我无法正确理解包装内容和匹配父属性Image 是否使用LinearLayout将图像和按钮设置为相同高度?,image,button,height,Image,Button,Height,我使用的是带有weightSum的LinearLayout,因此我可以设计通用屏幕,以在所有屏幕大小上运行。可能我无法正确理解包装内容和匹配父属性 问题可能是图像视图和按钮高度。尝试将其设置为匹配\u父项而不是换行\u内容: <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="0dp" androi
问题可能是图像视图和按钮高度。尝试将其设置为匹配\u父项而不是换行\u内容:
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="5">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/image01"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="Percent Calculator"
android:textSize="15dp"
android:layout_weight="3"
android:id="@+id/btnPCalculator"/>
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
您应该使用match_parent,以便文本视图和按钮高度都可以填充LinearLayout中的所有可用空间。如果使用“换行”内容,它们将只占用所需的空间,而忽略其余可用空间。当我对图像和按钮使用“匹配父对象”时,它们占用整个屏幕空间。实际上,我使用两个线性布局。第一个具有垂直方向,垂直填充7行块(图像+按钮),在该垂直布局中,每行块(图像+按钮)都有其自身的水平线性布局,可根据其重量调整图像+按钮+空白空间(视图)。Ok。我编辑了我的帖子并粘贴了整个xml代码。我应该怎么做才能使图像和按钮具有相同的高度?
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="5">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/image01"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="Percent Calculator"
android:textSize="15dp"
android:layout_weight="3"
android:id="@+id/btnPCalculator"/>
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>