0
나는 부모 레이아웃으로 cardview를 사용하고 있습니다. 그 cardview 안쪽에 나는 항목의 listview를 팽창시키고있다. 지금 당장 cardview의 고정 된 높이가 있지만 listview의 항목을 기반으로 높이를 동적으로 조정하려고합니다. 이건 내 아이 뷰의 XML입니다목록 뷰의 항목을 기준으로 카드 뷰의 높이를 조정합니다.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/shelfShareLinearlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:padding="20dp">
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
:
이
내 부모 XML입니다<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/shelfShareMasterLL"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/frontalRodShareCardView"
android:layout_width="585dp"
android:layout_height="500dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="15dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:id="@+id/shelfShareMasterRL"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/deleteSlefShareCard"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_marginRight="40dp"
android:layout_marginTop="10dp"
android:visibility="invisible"
android:background="@drawable/round_corner"
android:drawableTop="@drawable/ic_delete_black_24dp"
android:paddingTop="10dp" />
<TextView
android:id="@+id/shelfShareHeadingTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="Frontal Rod Share"
android:textSize="20sp" />
<CheckBox
android:id="@+id/noFrontalRodShareCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/shelfShareHeadingTextView"
android:visibility="invisible"
android:layout_toLeftOf="@+id/deleteSlefShareCard"
android:layout_marginRight="20dp"
android:text="No Frontal Rod Share" />
<ListView
android:id="@+id/shelfShareProductListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/shelfShareHeadingTextView">
</ListView>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
이 내가 아이 뷰를 팽창하고 여기에 목록을 표시하고 있습니다 방법은 다음과 같습니다
ArrayList<Products> shelfShareList = new ArrayList<Products>();
final LinearLayout shelfShareLL = (LinearLayout) view.findViewById(R.id.shelfShareLinearlayout);
final View shelfShareChildView = getActivity().getLayoutInflater().inflate(R.layout.cardviewshelfshare, null);
shelfShareLL.addView(shelfShareChildView);
ListView listView = (ListView) shelfShareChildView.findViewById(R.id.shelfShareProductListView);
Cursor crs = database.rawQuery(//My query, null);
while (crs.moveToNext()){
shelfShareList.add(//data from query);
}
listView.setAdapter(new ProductsAdapter(getActivity(), shelfShareList));
crs.close();
당신은 그 안에 카드 뷰와 상대 레이아웃 모두에 대해 'wrap_content'로 높이를 사용하려고합니까? –
나는 이것을 이미 시도했지만 나에게 도움이되지 않았다. –
나는 cardview, relativelayout 및 listview height를 wrap_content로 설정해야한다고 생각한다. – Lucky