首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在添加到RelativeLayout时更改GridView

在添加到RelativeLayout时更改GridView
EN

Stack Overflow用户
提问于 2018-12-05 02:18:41
回答 1查看 28关注 0票数 1

我有这样一个xml文件:

更新

代码语言:javascript
复制
     <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".ProgramsFragment"
android:background="@color/colorPrimaryDark">

        <!-- TODO: Update blank fragment layout -->


        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <GridView
                    android:id="@+id/gridView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:numColumns="auto_fit"
                    android:columnWidth="200dp"
                    android:layout_marginTop="16dp"
                    android:layout_marginRight="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginBottom="16dp"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:text="@string/your_articles"
                    android:gravity="center_horizontal"
                    android:textStyle="bold"/>
            </LinearLayout>
        </ScrollView>
    </FrameLayout>

我的目标是制作一个可滚动的布局,其中包含GridView和TextView。TextView应该把我放在GridView下面。当我运行我的程序时,GridView变小了,我不知道为什么。可能在textview中没有什么可以以这种方式改变GridView大小(正如我所认为的)。但也许我错了,因为当我删除TextView、RelativeLayout和ScrollView时,一切都正常工作。你怎么了?这是我的问题的一个屏幕:

UPD2

我通过这种方式添加到GridView:

代码语言:javascript
复制
private final String[] programs = {"Slim body for a four weeks", "Exercises for woman at home", "Effective exercises for biceps at home",
        "Program of effective trainings twice a week", "Training on a horizontal bar for increasing muscle mass",
        "Fitness program for woman: trainings at home at in gym"};
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,programs);
    GridView gridView = view.findViewById(R.id.gridView);
    gridView.setAdapter(adapter);

UPD3

我在这个文件中添加了android:background="@color/colorPrimaryDark"行,结果显示在屏幕上

。据我所知,整个片段采用了布局的这一部分。但是为什么呢?有一些几乎相同的碎片,它们占据了所有的地方。

EN

回答 1

Stack Overflow用户

发布于 2018-12-05 02:27:21

您应该使用linearlayout而不是relativelayout。此外,您还可以使用nestedscrollview。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53619174

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档