I am making phonebook, it works, but if screen resolution is smaller than content height, not all items of ListView shows, they left behind: (see last item)
But if content wrap to screen height, it shows good:
How can i fix this?
My codes:
CardView Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/phone_cv"
app:cardElevation="3dp"
app:contentPadding="10dp"
app:cardCornerRadius="3dp"
android:backgroundTint="#ffffff"
android:layout_marginBottom="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/phone_cv_person_name"
android:text="organisation name"
android:textSize="18sp"
android:textColor="#000000"
/>
<View
android:layout_height="1dp"
android:layout_width="match_parent"
android:background="#000000"
android:layout_marginTop="4dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/phone_cv_person_doljnost"
android:text="Limpus Dda Lorem"
android:visibility="gone"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/phone_cv_list"
android:scrollbars="none"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
My (custom) List View Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/phone_persons_list_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Name"
android:textSize="14sp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:paddingTop="1dp"
android:paddingBottom="0dp"
android:textColor="#000"
/>
<TextView
android:id="@+id/phone_persons_list_otdel"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="Otdel"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:paddingTop="1dp"
android:paddingBottom="0dp"
android:visibility="gone"
android:textColor="#CC000000"
android:textSize="12sp"
/>
<TextView
android:id="@+id/phone_persons_list_doljnost"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="Doljnost"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:paddingTop="1dp"
android:paddingBottom="0dp"
android:textColor="#CC000000"
android:visibility="gone"
android:textSize="12sp"
/>
<View
android:layout_height="0.5dp"
android:layout_width="match_parent"
android:background="#11EEEEEE"
android:layout_marginTop="4dp"
/>
</LinearLayout>
Setting cardview by next code:
mRecyclerView = (RecyclerView) findViewById(R.id.phones_rv);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new RVAdapter(data);
mRecyclerView.setAdapter(mAdapter);
Inside of RVAdapter i am setting listview adapter:
final PhoneNumbersContactListAdapter mAdapter = new PhoneNumbersContactListAdapter(mContext, mDataset.get(position).getPhGosData());
holder.mListView.setAdapter(mAdapter);
getTotalHeightOfListView(holder.mListView);
And then, with getTotalHeightOfListView function i am dynamically setting listview height:
public static void getTotalHeightofListView(ListView listView) {
ListAdapter mAdapter = listView.getAdapter();
int totalHeight = 0;
for (int i = 0; i < mAdapter.getCount(); i++) {
View mView = mAdapter.getView(i, null, listView);
mView.measure(
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
totalHeight += mView.getMeasuredHeight();
Log.w("HEIGHT" + i, String.valueOf(totalHeight));
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight
+ (listView.getDividerHeight() * (mAdapter.getCount() - 1));
listView.setLayoutParams(params);
listView.requestLayout();
}