我想在我的xml中这样做。目前我正在这样做:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.MainActivity">
<ImageView
android:id="@+id/main_drawable_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/text" />
<LinearLayout
android:id="@+id/main_drawable_logo"
android:layout_width="match_parent"
android:layout_below="@id/main_drawable_text"
android:layout_height="wrap_content">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:src="@drawable/logo" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_below="@id/main_drawable_logo"
android:layout_height="wrap_content">
<TextView
android:id="@+id/credits"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:text="@string/credits" />
</LinearLayout>
</RelativeLayout>
在我的测试设备中,我只获得了@drawable/logo
的一部分,剩下的就像信用证的文本一样掉在了屏幕之外。我当然可以调整重量,直到我得到所需的结果,但我怎样才能确保我会在所有设备上得到预期的结果?
我想要的是main_drawable_text
总是匹配屏幕的宽度(从边距到边距),credits
始终位于屏幕的底部,drawable_logo
已缩放以适合它们之间的自由空间,但具有原始的宽高比。
答案 0 :(得分:1)
如果我完全理解您要设计的用户界面,则不需要LinearLayout
但只需要现有的RelativeLayout
,并且在其中您可以根据其他位置放置您的元素(使用android:layout_above
,android:layout_below
等等。保持可绘制使用的原始比率android:scaleType="fitCenter"
。
这是一个显示(我的解释)你想要的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<ImageView
android:id="@+id/main_drawable_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@drawable/text"/>
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_above="@id/credits"
android:layout_below="@id/main_drawable_text"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@drawable/logo"/>
<TextView
android:id="@+id/credits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="@string/credits"/>
</RelativeLayout>