android - 添加到 RelativeLayout 时更改 GridView
问题描述
我有这样一个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"
在这个文件中添加了行,结果在屏幕上。据我了解,整个片段占据了布局的这一部分。但为什么?有一些几乎相同的片段,占据了所有的地方。
解决方案
您应该使用linearlayout
而不是relativelayout
. 此外,您可以使用nestedscrollview。
推荐阅读
- azure - Azure Web App Blazor 服务器 - 无法启动传输“WebSockets”:错误:传输出现错误
- linux - 在python中查找所有超过一分钟的文件
- visual-studio-code - VS CODE 显示一些奇怪的模式
- r - geom_line() 当缺少某些季度时省略整个时间序列
- java - 如何绑定 SQL 查询和 GetMapping
- animation - UE4在运行时导入动画
- python - 我的 ResNet 50 实施的训练和测试精度为 0.1。我在实施中做错了什么?
- javascript - 如何制作一个变量不会失去其价值的全局模块?
- amazon-web-services - Campaign 挂钩精确定位的示例 lambda 函数
- oracle - 使用外部表时最近 BADFILE 的位置和文件名