Java Android ImageView超越线性布局
我正在开发一个android应用程序,布局如下图所示: 该布局包含两个主要线性布局:占设备高度90%的水平布局和占设备高度10%的垂直布局。在水平线性布局内部有三个线性布局(两个红色,一个包含imageview)。每个红色布局为屏幕宽度的10%,包含ImageView的布局为80%。以下是xml代码:Java Android ImageView超越线性布局,java,android,android-layout,Java,Android,Android Layout,我正在开发一个android应用程序,布局如下图所示: 该布局包含两个主要线性布局:占设备高度90%的水平布局和占设备高度10%的垂直布局。在水平线性布局内部有三个线性布局(两个红色,一个包含imageview)。每个红色布局为屏幕宽度的10%,包含ImageView的布局为80%。以下是xml代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.andro
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="0.9"
android:weightSum="1"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.1"
android:background="#ff0000" >
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:layout_weight="0.8" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:src="@drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.1"
android:background="#ff0000" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.1"
android:background="#000000" >
</LinearLayout>
</LinearLayout>
问题是,当我将PNG图像(1036px X 730px)设置为ImageView的源时,ImageView将越过底部线性布局(黑色布局),两个红色布局将被压缩
我的问题是如何解决这个问题,并在所有类型的平板电脑上使用相同的布局功能?试试这种方法,希望这能帮助您解决问题。
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="0.90">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.10"
android:background="#ff0000" >
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_weight="0.80" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.10"
android:background="#ff0000" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="0.10"
android:background="#000000" >
</LinearLayout>
</LinearLayout>
您可以发布布局的图像吗?当您设置png图像(1036px X 730px)时,非常感谢它的工作,我可以对其进行处理以使图片不会被拉伸吗?当然,请将此:android:scaleType=“fitXY”替换为:android:adjustViewBounds=“true”为ImageViewThank再次感谢Haresh@user3012088 FYI嵌套权重不利于性能。但是我想没有别的选择了:)谢谢你,我会考虑的