Android:使ImageView匹配另一个 View 的高度

标签 android layout imageview height android-linearlayout

我在设计应用程序布局时遇到问题。这就是我想要得到的:

=========================================================
|  =============   ================   ================  |
|  |           |   | LinearLayout |   | LinearLayout |  |
|  |           |   | ============ |   | ============ |  |
|  |           |   | | TextView | |   | | TextView | |  |
|  | ImageView |   | ============ |   | ============ |  |
|  |           |   | ============ |   | ============ |  |
|  |           |   | | TextView | |   | | TextView | |  |
|  |           |   | ============ |   | ============ |  |
|  |           |   | ============ |   | ============ |  |
|  |           |   | | TextView | |   | | TextView | |  |
|  |           |   | ============ |   | ============ |  |
|  =============   ================   ================  |
=========================================================

这是我到目前为止所做的(为了清楚起见,我删除了 id 和其他内容):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center_vertical" >


    <ImageView
        android:contentDescription="@string/logo"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="left|center_vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="right|center_vertical"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true" />

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:singleLine="true" />

    </LinearLayout>

</LinearLayout>

我的问题是我想使用高分辨率图像并将它们缩小以匹配旁边最高的线性布局。我的想法是让 android 缩小低 dpi 设备上的图像,因此对所有平台使用相同的图像和布局。

就像现在一样,主容器的高度与图像高度一样大。我想要的是主容器高度与“最高”线性布局相同,并强制 ImageView 按比例缩小以适合主容器。

有什么想法吗?

谢谢!

PD:请原谅我的英语! :$

最佳答案

所有 View 的高度宽度和所有这些东西都是在 Activity 的 onMeasure() 中测量的。值得注意的一点是,任何 View 的 onMeasure() 都在 onDraw() 之前执行,并且可以在 n-次数。因此,最好在其 onMeasure() 中计算 LinearLayout 的宽度和高度。

关于Android:使ImageView匹配另一个 View 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17801385/

相关文章:

java - 更改方向时操作栏选项卡中的错误

java - 使用android时关闭android View :layout_centerVertical ="true"?

javascript - CSS/jQuery : Complex editable content inside layout

android - 如何在 ListView (Kotlin) 中每行添加多个图像,例如 3 张图像

image - 关于带有小图标的 TextField

android - 如何在 Android 中创建圆形 ImageView?

Android edittext - 输入 "text selection mode"

android - 创建简单的 Google Cardboard

android - 将图像从 Android 发送到 Sony Smart Watch 2

css - 如何将侧边栏列中的 div 固定到底部?