我有以下问题。我正在开发android应用。我的问题是从“人像”到“风景”的过渡(从垂直到水平的过渡)。
“肖像”显示正常工作。显示“风景”时,图像显得失真。我该如何解决?
这很好...
这很糟糕...
这是我的布局xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:src="@drawable/rsz_pprlogo"
android:textSize="36sp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<ImageButton
android:id="@+id/legislativa"
android:onClick="OnButtonClick"
android:src="@drawable/rsz_legislativa"
android:
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@android:color/transparent"
android:padding="0dp"
android:scaleType="fitXY"
android:text="Button 1" />
<ImageButton
android:src="@mipmap/ic_launcher"
android:text="Button 2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<ImageButton
android:src="@mipmap/ic_launcher"
android:text="Button 3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/transparent"
android:padding="0dp"
android:gravity="center"/>
<ImageButton
android:src="@mipmap/ic_launcher"
android:text="Button 4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<ImageButton
android:src="@mipmap/ic_launcher"
android:text="Button 5"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"/>
<ImageButton
android:src="@mipmap/ic_launcher"
android:text="Button 6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<ImageButton
android:src="@mipmap/ic_launcher"
android:text="Button 7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"/>
<ImageButton
android:src="@mipmap/ic_launcher"
android:text="Button 8"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
有什么方法可以修复“风景”视图?谢谢。
您有一个在fitXY上设置了scaleType的ImageButton,这就是引起奇怪效果的原因。只需尝试不使用scaleType或尝试其他值,直到找到更适合您需求的值即可。您可以在此处阅读有关比例尺类型的更多信息:https://developer.android.com/reference/android/widget/ImageView.ScaleType
这是带有scaleType的ImageButton:
<ImageButton
android:id="@+id/legislativa"
android:onClick="OnButtonClick"
android:src="@drawable/rsz_legislativa"
android:
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@android:color/transparent"
android:padding="0dp"
android:scaleType="fitXY"
android:text="Button 1" />
此外,有一个没有任何规范的标签,最好将其删除。最后,我建议您使用ConstraintLayout而不是嵌套的LinearLayouts