我尝试使用顶部的两个TextView和布局底部的ImageView进行布局。但是我对ImageView的scalingtyp有问题。图像应始终调整大小,但始终在中心。这是我的问题的图片:
我希望你能解决我的问题 这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent"
android:orientation="vertical" >
<TextView
android:id="@+id/textViewGameOver1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="top|center_horizontal"
android:gravity="center"
android:text="TextView1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textViewGameOver2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textViewGameOver1"
android:layout_centerHorizontal="true"
android:layout_gravity="top|center_horizontal"
android:gravity="center"
android:text="TextView2"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="@+id/imageViewGameOver"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_below="@+id/textViewGameOver2"
android:layout_centerHorizontal="true"
android:layout_gravity="bottom|center_horizontal"
android:scaleType="fitEnd"
android:src="@drawable/sheldon_win" />
</RelativeLayout>
有人有想法解决这个问题吗?
祝你好运!
答案 0 :(得分:1)
您应该使用RelativeLayout
而不是LinearLayout
。这样您就可以将图像放在所需的位置,然后将ImageView
的大小设置为您想要的大小。
<ImageView
android:id="@+id/imageViewGameOver"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/sheldon_win" />
这应该将图像放在右下角,图像应该是图像文件的大小。如果要更改它,可以在dp&#39;中将宽度和高度设置为某个大小。