This may be the opposite question from Android GridView Items Resizing
I have a GridView that is set to display a custom layout made from a LinearLayout with a 9-patch background and a TextView. The LinearLayout has a 10dp padding set so the TextView stays in the center patch.
When I've tested data to expand the TextView, the LinearLayout also appears to expand (yay!) but the GridView is cutting off the bottom. In the image below, you can see that the bottom right element has the bottom-right curvature cut off.
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://ift.tt/nIICcg"
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>
activity_my_classes:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://ift.tt/nIICcg"
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>
How do I get the element or row to grow taller in response to a larger TextView child?
Aucun commentaire:
Enregistrer un commentaire