LinearLayout 无法正常工作
LinearLayout doesn't work properly
我怎样才能把 TextView
放在 ImageView
的正下方?
我写了下面的代码,但是它把 TextView
和边距放在图像下面,
我也为 ImageView
.
尝试了不同的 scaleType
<?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>
为 ImageView 添加 android:adjustViewBounds="true" 属性。将此设置为 true 将调整其边界以保留其可绘制对象的纵横比。
<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" />
您可以改用 relativeLayout,然后像这样将 textview 放在图像下方:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<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" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello"
android:layout_below="@id/list_row_logo"/>
</RelativeLayout>
我怎样才能把 TextView
放在 ImageView
的正下方?
我写了下面的代码,但是它把 TextView
和边距放在图像下面,
我也为 ImageView
.
scaleType
<?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>
为 ImageView 添加 android:adjustViewBounds="true" 属性。将此设置为 true 将调整其边界以保留其可绘制对象的纵横比。
<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" />
您可以改用 relativeLayout,然后像这样将 textview 放在图像下方:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<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" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello"
android:layout_below="@id/list_row_logo"/>
</RelativeLayout>