LinearLayout无法正常工作

时间:2016-01-07 10:43:59

标签: android android-linearlayout android-imageview

enter image description here
如何将TextView完全置于ImageView之下? 我编写下面的代码,但它将TextView的边距放在图像下方, 我还为scaleType尝试了不同的ImageView

<?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="match_parent"
    android:orientation="vertical">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/list_row_logo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:padding="0dp"
            android:src="@drawable/nature_bg" />
    </FrameLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello" />
</LinearLayout>

2 个答案:

答案 0 :(得分:0)

为ImageView添加android:adjustViewBounds="true"属性。将此设置为true将调整其边界以保留其drawable的纵横比。

<ImageView
      android:id="@+id/list_row_logo"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_margin="0dp"
      android:padding="0dp"
      android:adjustViewBounds="true"
      android:src="@drawable/beekeeper_logo" />

答案 1 :(得分:0)

您可以使用relativeLayout,并将textview放在图像下方:

>python3 test.py
[2.398782472571393, 2.3595238689519626, 2.37358552995787]
[1.0055455609592512, 1.007462347465074, 1.012826469701654]
[0.32564058749026437, 0.3303359144351621, 0.31772896318809885]