android - 将 ImageView 调整为 TextView 的高度

标签 android android-layout android-imageview textview

我的 LinearLayout 包含 2 个 TextView(TextView1 和 TextView2)和一个 ImageView。现在我希望 LinearLayout 始终具有固定高度,即 ThextView1 的高度,以便 ImageView 始终使用 fill_parent 将其图像调整为 TextView1 的高度。

 _____________________________________
|TextView1------------------ ImageView|
|TextView1 --- TextView2 --- ImageView|
|TextView1 ----------------- ImageView|

有点难以解释...ImageView 始终应具有 TextView1 的高度并调整其图像的大小(同时保持原始纵横比)。

这是否可以仅使用 layout-xml 来完成,还是我需要以编程方式来完成?

我希望你能帮助我:)

最佳答案

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        ... />

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

</LinearLayout>

我还没有测试过这个。你指的是这个吗?

关于android - 将 ImageView 调整为 TextView 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15602947/

相关文章:

android - 在 Google Play Integrity 中生成 Nonce 的正确方法是什么

java - 更改EditText的下划线/样式......而不是链接,并水平滚动文本

Android:交换2个 View 的位置

java - android:layout_weight 考虑 FrameLayout 中嵌入 ImageViewer 的大小

java - 可拖动的叠加层可以移出屏幕?

android - 如何在 Room 中插入具有一对多关系的实体

android - 访问 Android 中的嵌套布局

android - ScrollView 中 LinearLayout 下方的 RecyclerView

Android如何创建堆栈类图像背景

android - ListView 图片加载 Android