刚开始学Android,GridLayout布局,为什么界面总是超出屏幕?这是Layout的xml文件,求指点

Android 码拜 8年前 (2016-05-09) 2105次浏览
<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent” >

<TextView
android:id=”@+id/textView1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentLeft=”true”
android:layout_alignParentTop=”true”
android:text=”Choose an Image”  />
<Button
android:id=”@+id/loadPhotoButton”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_alignParentBottom=”true”
android:text=”Load New Photos”/>
<GridLayout
android:layout_below=”@id/textView1″
android:layout_above=”@id/loadPhotoButton”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:columnCount=”3″ >
<ImageView
android:id=”@+id/imageView1″
android:src=”@drawable/logo” />
<ImageView
android:id=”@+id/imageView2″
android:src=”@drawable/logo” />
<ImageView
android:id=”@+id/imageView3″
android:src=”@drawable/logo” />

</GridLayout>

</RelativeLayout>

解决方案

10

imageview里不写width和height属性真的可以么

10

这样看没有问题,但是应该是图片没设置宽高

30

引用:
Quote: 引用:

原因猜测是你的logo图片太大了,3张横着放放不下所以超出屏幕了

是图片的问题?那本人只能去修改图片了?有没有办法让通过程序让它本人调整呢?

把GridLayout 换成LinearLayout,然后设置 android:layout_weight=”1″ ,3等分就行了
<LinearLayout
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:layout_above=”@id/loadPhotoButton”
android:layout_below=”@id/textView1″
android:orientation=”horizontal” >
<ImageView
android:id=”@+id/imageView1″
android:layout_width=”0dp”
android:layout_height=”wrap_content”
android:layout_weight=”1″
android:src=”@drawable/aaa” />
<ImageView
android:id=”@+id/imageView2″
android:layout_width=”0dp”
android:layout_height=”wrap_content”
android:layout_weight=”1″
android:src=”@drawable/aaa” />
<ImageView
android:id=”@+id/imageView3″
android:layout_width=”0dp”
android:layout_height=”wrap_content”
android:layout_weight=”1″
android:src=”@drawable/aaa” />
</LinearLayout>


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明刚开始学Android,GridLayout布局,为什么界面总是超出屏幕?这是Layout的xml文件,求指点
喜欢 (0)
[1034331897@qq.com]
分享 (0)