【发布时间】:2018-12-04 18:18:41
【问题描述】:
我有这样一个xml文件:
UPD
<?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:
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",结果显示在屏幕上。据我了解,整个片段占据了布局的这一部分。但为什么?有一些几乎相同的片段,占据了所有的地方。
【问题讨论】: