NestedScrollView中的GridLayout,为什么我的列超出了视图空间?

3
基本上当我在Android Studio中创建一个新项目时,所有默认的活动都包含一个NestedScrollView。
如果我尝试将网格布局作为其唯一子项放入其中,那么列会超出屏幕大小。您可以在下面的图片中看到: enter image description here 这是添加了一个与(1,1)瓶子中的图像按钮相同的图像按钮,请注意按钮的宽度为wrap_content,但没有内容(葡萄酒是一个正方形的图标,设置为src,使用fitStart比例),但由于某种原因它覆盖了整个屏幕的大小。
我尝试了多种方法来使其工作,阅读了Stackoverflow后,我了解到应该使用android.support.v7.widget.GridLayout而不是网格布局,所以我这样做了。然后我读到应该添加一个线性布局作为父级,但没有成功。
以下是我的XML文件。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="it.giuseppi.alessandro.wine.Main">

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

<android.support.v7.widget.GridLayout
    android:layout_width="match_parent"
    android:layout_height="900dp"
    app:columnCount="3">

    <ImageButton
        android:layout_height="150dp"
        app:layout_column="0"
        android:id="@+id/imageButton"
        android:src="@drawable/premium"
        android:scaleType="fitStart"
        android:background="@color/yellow"
        android:baselineAlignBottom="false"
        app:layout_row="0"/>

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="150dp"
        android:id="@+id/imageButton2"
        android:src="@drawable/premium"
        android:scaleType="fitStart"
        app:layout_column="1"
        app:layout_row="1" />

</android.support.v7.widget.GridLayout>
</LinearLayout>

</android.support.v4.widget.NestedScrollView>

如果需要,我可以提供整个项目。
1个回答

0

请检查您的行设置和行大小。

 app:layout_column="1"
    app:layout_row="1" />

行的宽度等于设备的宽度。这意味着任何其他水平放置的项目都会出现在屏幕右侧。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接