ADK*_*ADK 5 xml android relativelayout android-layout
我正面临屏幕外的问题按钮显示RelativeLayout.ImageView不会缩放图片以给出按钮可见的位置.
是)我有的:

我想要的是:

码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical" >
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str"
android:textAppearance="@android:style/TextAppearance.Small"
android:textColor="?android:attr/textColorTertiary"
android:layout_centerHorizontal="true"
/>
<ru.mw.widget.DrawableImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:scaleType="centerCrop"
/>
<Button
android:id="@+id/processButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"
/>
Run Code Online (Sandbox Code Playgroud)
当我改变屏幕方向时出现问题:如果我在横向模式下使用Arun C Thomas的方法一切正常,但在纵向模式下我有这个(图像被左/右边缘裁剪):
预期结果:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical" >
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str"
android:textColor="?android:attr/textColorTertiary"
android:textAppearance="@android:style/TextAppearance.Small"
android:layout_centerHorizontal="true"
/>
<ru.mw.widget.DrawableImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:layout_above="@+id/processButton"
/>
<Button
android:id="@+id/processButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这就是解决方案
现在,为了实现更新的要求,请将上述布局添加到layout-land文件夹中res(如果您没有创建一个名为layout-landin的文件夹res),现在在默认layout文件夹中添加此 xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<ru.mw.widget.DrawableImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
/>
<Button
android:id="@+id/processButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"
android:text="@string/str" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/imageView"
android:layout_centerHorizontal="true"
android:text="@string/str"
android:textColor="?android:attr/textColorTertiary" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
就是这样。
| 归档时间: |
|
| 查看次数: |
2600 次 |
| 最近记录: |