android 垂直LinearLayout的高度

3qpi33ja  于 2023-09-29  发布在  Android
关注(0)|答案(1)|浏览(91)

我试着写下面的对话:

上面的图片显示了我现在的情况。在中心,有一个垂直滚动的窗格列表。每个窗格的左侧有一个ImageView,右侧有三个元素:一个TextView、另一个TextView和一个Button。
下面是如何写的:

<LinearLayout
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:orientation="horizontal"
   <!-- .... -->                 >

   <ImageView
       android:scaleType="fitCenter"
       android:layout_width="0dp"
       android:layout_height="match_parent"
       android:layout_gravity="top"
       android:layout_weight="0.5"
       <!-- .... -->            >

   <LinearLayout
       android:layout_width="0dp"
       android:layout_height="match_parent"
       android:orientation="vertical"
       android:layout_weight="1.0"
       <!-- .... -->            >

       <TextView
          android:gravity="top|start"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          <!-- .... -->                    />

       <TextView
          android:gravity="top|start"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          <!-- .... -->                    />

       <Button
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="bottom"
          <!-- .... -->                    />

   </LinearLayout>
</LinearLayout>

现在,这几乎达到了预期的效果。我正在努力解决的问题是:
我想由三个元素(两个TextViews和Button)的组合高度来确定单个窗格的高度。不幸的是,它是由左图像的高度确定的(在缩放之前,即在android应用scaleType=“fitCenter”之前-原始图像要大得多,并且在大多数手机上会被缩小)。
所以,正如你所看到的,每个窗格都太高了,在每个按钮下面留下了不必要的空白空间。
我该如何纠正这个问题?
顺便说一句,这是免费和开源的Magic Cube应用程序的一部分。你可以在这里下载:
https://play.google.com/store/apps/details?id=org.distorted.magic&pli=1
发现问题所在

bwitn5fc

bwitn5fc1#

解决了它-只需添加

android:adjustViewBounds="true"

到'ImageView'部分:)

相关问题