Android GridView项未展开以显示内容

Android GridView项未展开以显示内容,android,android-layout,gridview,nine-patch,Android,Android Layout,Gridview,Nine Patch,这可能与我们的问题相反 我有一个GridView,它被设置为显示一个自定义布局,该布局由一个带有9块背景的线性布局和一个TextView组成。LinearLayout有一个10dp的填充设置,因此TextView保留在中间补丁中 当我测试数据以展开TextView时,LinearLayout也会展开yay!但GridView正在切断底部。在下图中,您可以看到右下角元素的右下角曲率被截断 MyClasses.java: @Override protected void onCreate(Bundl

这可能与我们的问题相反

我有一个GridView,它被设置为显示一个自定义布局,该布局由一个带有9块背景的线性布局和一个TextView组成。LinearLayout有一个10dp的填充设置,因此TextView保留在中间补丁中

当我测试数据以展开TextView时,LinearLayout也会展开yay!但GridView正在切断底部。在下图中,您可以看到右下角元素的右下角曲率被截断

MyClasses.java:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my_classes);
    notebookGrid = (GridView)findViewById(R.id.NotebookGrid);

    ArrayList<String> class1 = new ArrayList<>(Arrays.asList("1", "Ms. Soldan's Class"));
    ArrayList<String> class2 = new ArrayList<>(Arrays.asList("2", "Ms. Perry's Class"));
    ArrayList<String> class3 = new ArrayList<>(Arrays.asList("3", "Ms. Panjwani's Class"));
    ArrayList<String> class4 = new ArrayList<>(Arrays.asList("4", "Ms. Smith's Really Awesome Super Cool Class of Many Geniuses"));

    ArrayList<ArrayList<String>> classArray = new ArrayList<>();
    classArray.add(class1);
    classArray.add(class2);
    classArray.add(class3);
    classArray.add(class4);
    notebookGrid.setAdapter(new MyClassesAdapter(this, classArray));
}
MyClassesAdapter.java:

public View getView(int position, View convertView, ViewGroup parent) {
    ArrayList<String> thisClass = getItem(position);
    ViewHolder vh;
    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.grid_class_notebook, parent,false);
        vh = new ViewHolder(convertView,R.id.NotebookTitle);
        convertView.setTag(vh);
    } else {
        vh = (ViewHolder)convertView.getTag();
    }
        vh.TitleView.setText(thisClass.get(1));
    return convertView;
}
grid_class_notebook.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:background="@drawable/notebook">

    <Space
        android:layout_width="wrap_content"
        android:layout_height="10dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:gravity="center"
        android:background="@color/White"
        android:padding="10dp"
        android:textStyle="bold"
        android:textSize="12sp"
        android:id="@+id/NotebookTitle"
        />
</LinearLayout>
活动我的课程:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="10dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="22sp"
        android:gravity="left"
        android:padding="25dp"
        android:text="@string/classes_title"
        android:textStyle="bold"/>

    <GridView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:numColumns="2"
        android:padding="15dp"
        android:id="@+id/NotebookGrid"/>
</LinearLayout>
<GridView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:numColumns="2"
    android:padding="15dp"
    android:id="@+id/NotebookGrid"/>

我如何让元素或行变高以响应更大的TextView子元素?

因此我只花了一个月的时间来回答自己的问题。这里发生的事情是GridView本身很短,但项目本身的大小实际上是适当的。我从来没有想过要尝试滚动笔记本,但今天我这样做了,剩下的图像出现了

基本上,错误在于GridView的内容高度为wrap_。我已经将其更改为0dp的高度,并添加了一个weight=1的标记,因为我最终将在GridView下面添加一些其他元素。活动\我的\类的新xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="10dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="22sp"
        android:gravity="left"
        android:padding="25dp"
        android:text="@string/classes_title"
        android:textStyle="bold"/>

    <GridView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:numColumns="2"
        android:padding="15dp"
        android:id="@+id/NotebookGrid"/>
</LinearLayout>
<GridView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:numColumns="2"
    android:padding="15dp"
    android:id="@+id/NotebookGrid"/>

添加活动\u我的\u类的代码。xml添加了活动\u我的\u类