嗨我用相对布局/ scrollview / gridlelayout创建一个活动,但我的应用程序没有打开。我的错是什么?在scrollview中不使用gridlelayout吗? 嗨我用相对布局/ scrollview / gridlelayout创建一个活动但我的应用程序没有打开。我的错是什么?在scrollview中不使用gridlelayout吗?
非常感谢。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.peg.MainActivity">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="1"
android:rowCount="1">
<Button
android:id="@+id/s"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_margin="20dp"
android:layout_row="0"
android:background="@drawable/s" />
<Button
android:id="@+id/hur"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_margin="20dp"
android:layout_row="1"
android:background="@drawable/hur" />
<Button
android:id="@+id/mil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_margin="20dp"
android:layout_row="0"
android:background="@drawable/mil" />
<Button
android:id="@+id/ysr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_margin="20dp"
android:layout_row="1"
android:background="@drawable/ysr" />
</GridLayout>
</ScrollView>
</RelativeLayout>
答案 0 :(得分:0)
我认为您的问题在于项目数量您有4个按钮但只有一行且只有一个单元格,请尝试:
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"
android:rowCount="2">
如果您的观点变得更复杂,我建议您使用RecyclerView。
答案 1 :(得分:0)
试试这个
您在Gridlayout中增加了android:columnCount="2"
和android:rowCount="2"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"
android:orientation="horizontal"
android:rowCount="2">
<Button
android:id="@+id/s"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_margin="20dp"
android:layout_row="0"
android:background="@mipmap/ic_launcher" />
<Button
android:id="@+id/hur"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_margin="20dp"
android:layout_row="1"
android:background="@mipmap/ic_launcher" />
<Button
android:id="@+id/mil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_margin="20dp"
android:layout_row="0"
android:background="@mipmap/ic_launcher" />
<Button
android:id="@+id/ysr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_margin="20dp"
android:layout_row="1"
android:background="@mipmap/ic_launcher" />
</GridLayout>
</ScrollView>
</RelativeLayout>
<强>输出强>