我有一个带有ImageView和TextView的框架布局。我打算把这段文字放在图片的中央。问题是图像不适合,ImageView不会包装内容的高度好。看看这幅画:
我需要它看起来像这样:
我尝试混合高度和(包装内容和匹配父母),但图片仍然不适合。这是xml:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:srcCompat="@drawable/tvrdjava"
android:id="@+id/imageView3" />
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/textView6"
android:textAlignment="center"
android:textColor="@android:color/white"
/>
</FrameLayout>
图片位于不同分辨率的可绘制文件夹中(hdpi、mdpi、xhdpi、xhdpi、xxhdpi )。
发布于 2017-03-14 14:36:14
您应该尝试使用类似的方法,而不是使用RelativeLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
app:srcCompat="@drawable/ok"/>
<TextView
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="30sp"
android:text="TextView"/>
</RelativeLayout>
发布于 2017-03-14 14:56:08
感谢@MatPag的想法。将此帧布局放置在LinearLayout (垂直)中是可行的。
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@drawable/tvrdjava"
android:id="@+id/imageView8"
android:adjustViewBounds="true"
android:cropToPadding="false" />
<TextView
android:text="TrTemp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/textView3"
android:textColor="@android:color/holo_blue_dark"
android:textAlignment="center"
android:gravity="center"
/>
</FrameLayout>
发布于 2017-08-21 11:16:01
这对我有用。
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/homepage_background_imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/background_homepage"/>
</FrameLayout>
https://stackoverflow.com/questions/42787161
复制相似问题