【发布时间】:2014-05-07 14:44:20
【问题描述】:
您好,我的应用程序中的一个活动有问题,它没有填满所有可用空间这里是屏幕截图
现在这里看起来不错,它的右侧是一个相对布局,里面有按钮,一个网格布局包含所有动物当点击相对布局中的按钮时,它会更改网格布局中的图像,但是当它显示在平板电脑上时,动物占据左上角而不是拉伸以满足其他布局我的问题是我可以做些什么来使网格布局填充这个空间还是设置网格视图更实用? 这是我的xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MusicActivity"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/secondLayout"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true">
<Button
android:layout_width="75dp"
android:layout_height="75dp"
android:id="@+id/Button1"
android:background="@drawable/choose_animals2"/>
<Button
android:layout_width="75dp"
android:layout_height="75dp"
android:id="@+id/Button2"
android:background="@drawable/choose_letters"
android:layout_below="@+id/Button1"
android:layout_alignParentLeft="true" />
<Button
android:layout_width="75dp"
android:layout_height="75dp"
android:id="@+id/Button3"
android:background="@drawable/piano_icon"
android:layout_below="@+id/Button2"
android:layout_alignParentLeft="true" />
<Button
android:layout_width="75dp"
android:layout_height="75dp"
android:id="@+id/Button4"
android:background="@drawable/drum_icon0"
android:layout_below="@+id/Button3"
android:layout_alignParentLeft="true" />
<Button
android:layout_width="75dp"
android:layout_height="75dp"
android:id="@+id/Button5"
android:background="@drawable/choose_numbers"
android:layout_below="@+id/Button4"
android:layout_alignParentLeft="true" />
<Button
android:layout_width="75dp"
android:layout_height="75dp"
android:background="@drawable/nxtbtn"
android:id="@+id/Button6"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" />
</RelativeLayout>
<ScrollView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:fillViewport="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/secondLayout">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="2"
android:rowCount="13">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:layout_column="0"
android:layout_row="0"
android:padding="5dp"
android:background="@drawable/lion_icon"
android:contentDescription="@string/lionhead"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton2"
android:layout_column="1"
android:layout_row="0"
android:background="@drawable/dog_icon"
android:padding="5dp"
android:contentDescription="@string/doghead"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton3"
android:background="@drawable/cat_icon"
android:padding="5dp"
android:layout_column="0"
android:layout_row="1"
android:contentDescription="@string/cathead"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton4"
android:layout_column="1"
android:layout_row="1"
android:padding="5dp"
android:background="@drawable/duck_icon"
android:contentDescription="@string/duckhead"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton5"
android:padding="5dp"
android:background="@drawable/monkey_icon"
android:layout_column="0"
android:layout_row="2"
android:contentDescription="@string/monkeyhead"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton6"
android:background="@drawable/sheep_icon"
android:padding="5dp"
android:layout_column="1"
android:layout_row="2"
android:contentDescription="@string/sheephead"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton7"
android:padding="5dp"
android:background="@drawable/pig_icon"
android:layout_column="0"
android:layout_row="3"
android:contentDescription="@string/pighead"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton8"
android:padding="5dp"
android:background="@drawable/ele_icon"
android:layout_column="1"
android:layout_row="3"
android:contentDescription="@string/elephanthead"/>
</GridLayout>
</ScrollView>
</RelativeLayout>
感谢所有建议
【问题讨论】:
-
发布您的布局 xml。
-
你试过用 android:stretchMode="XXX" 做实验吗? / android:numColumns="auto_fit" / android:columnWidth="" 平板电脑屏幕尺寸
-
我对 android 来说不是很新我的拉伸模式目前的网格布局是 collumnwidth @Hamid Shatu 更新以包含代码
-
那是怎么编译的,
android:orientation只适用于LinearLayout不是吗? -
是的,从前它是一个线性布局,高度和宽度现在提供方向,所以谢谢你我会把它拿出来,但我知道有一些问题,但我们可以请专注于问题
标签: android grid-layout