【发布时间】:2017-07-29 16:39:27
【问题描述】:
我想创建一个如下所示的布局: https://gyazo.com/2a08bcd731fb1cfeb07e72f75bc05e7e 我应该为此使用什么,它适合所有设备?
屏幕是我的,但问题是它不适合所有屏幕尺寸。 在某些设备上,它看起来像这样: https://gyazo.com/84d878061234c25ae872d4ed2491f2f4
这是我用来编写此布局的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_column="0"
android:layout_row="0"
android:text="Button"/>
<Button
android:id="@+id/Button2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_column="1"
android:layout_row="0"
android:text="Button"/>
<Button
android:id="@+id/Button3"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_column="0"
android:layout_row="1"
android:text="Button"/>
<Button
android:id="@+id/Button4"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_column="1"
android:layout_row="1"
android:text="Button"/>
//and 200 buttons more
</GridLayout>
</ScrollView>
如何编写适合各种屏幕尺寸的这样的布局? 重要的是 ScrollView
【问题讨论】:
-
使用自定义适配器搜索
GridAdapter以获取Gride view或RecyclerView -
是否可以不在活动中编写任何代码来做到这一点?我只想要按钮的排列方式
-
我不确定你的意思,但它可以是一个使用
GridAdapter就像你用ListView做的一样,也可以通过使用RecyclerViewAFAIK 来实现!
标签: android xml button gridview layout