Android Studio,网格布局绝不相同
问题描述:
当我在Android Studio上工作时,网格视图看起来很棒,当我在模拟器中运行它时,网格视图看起来损坏,并且它在不同版本的android中有所不同。Android Studio,网格布局绝不相同
任何人都可以帮助我解决这个问题吗?
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:columnCount="4"
android:orientation="horizontal" >
<Button android:text="$3" />
<Button android:text="$5" />
<Button
android:layout_gravity="fill"
android:layout_columnSpan="2"
android:text="upis" />
<Button android:text="$10" />
<Button android:text="$15" />
<Button android:text="$160" />
<Button android:text="$180" />
<Button android:text="$20" />
<Button android:text="$25" />
<Button android:text="$200" />
<Button android:text="$220" />
<Button android:text="$20" />
<Button android:text="$25" />
<Button android:text="$200" />
<Button android:text="$220" />
<Button android:text="$20" />
<Button android:text="$25" />
<Button android:text="$200" />
<Button android:text="$220" />
<Button android:text="$20" />
<Button android:text="$25" />
<Button android:text="$200" />
<Button android:text="$220" />
<Button android:text="$20" />
<Button android:text="$25" />
<Button android:text="$200" />
<Button android:text="$220" />
<Button android:text="$20" />
<Button android:text="$25" />
<Button android:text="$200" />
<Button android:text="$220" />
<Button android:text="$20" />
<Button android:text="$25" />
<Button android:text="$200" />
<Button android:text="$220" />
</GridLayout>
first emulator pitcure, andriod 4 second emulator pitcure, andriod 5
谁能帮我这个,或者是还有什么选择吗?
答
在您GridLayout
,请尝试使用:
android:layout_width="match_parent"
android:layout_height="match_parent"
你的代码的问题是,它没有考虑在帐户的不同的屏幕尺寸。的确,
android:layout_width="wrap_content"
android:layout_height="wrap_content"
GridLayout
的大小考虑了按钮的大小。由于按钮的尺寸未定义,因此android:layout_width
和android:layout_height
的值为默认值。
您的更改与Android版本无关。大多数情况下,这个问题是不同的屏幕尺寸。你可以通过让你的'GridLayout'填充可用空间来帮助第二种场景('宽度和高度'为'match_parent',而不是'wrap_content')。您可能还需要对窗口小部件大小进行一些更改(请参阅[文档](https://developer.android.com/reference/android/support/v7/widget/GridLayout.html)中的“超额空间分配”) 。 – CommonsWare