반응형
https://wefu.tistory.com/64
이분 글 보고 따라하니깐 잘됨 ^^b 짱짱천재 ~~!
list.xml
처음 | androidx.core.widget.NestedScrollView
중간 | LinearLaout
중간 안 | ListView
ScrollView는 한개의 자식만을 취급하므로 LinearLaout으로 ListView들을 묶어줘야한다.
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
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"
android:orientation="vertical"
tools:context=".CallFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" 성범죄 관련 신고"
android:textSize="14sp"
android:background="#F2F2F2"/>
<ListView
android:id="@+id/reportListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" 성범죄 관련 법무법인"
android:textSize="14sp"
android:background="#F2F2F2"/>
<ListView
android:id="@+id/lawfirmListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
MainActivity.java
앱 기능 상 Fragment에서 구현
public class CallFragment extends Fragment {
//report list view
private ListView reportListView;
private CallReportListViewAdapter reportAdpater;
//lawfirm list view
private ListView lawfirmListView;
private CallReportListViewAdapter lawfirmAdpater;
//스크롤 가능하게 만들기
public static void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = (ListAdapter) listView.getAdapter();
if (listAdapter == null) return;
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
listView.requestLayout();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_call_list, container, false);
//report list view
reportAdpater = new CallReportListViewAdapter();
reportListView = (ListView) v.findViewById(R.id.reportListView);
reportListView.setAdapter(reportAdpater);
reportAdpater.addItem("사이버 경찰청", "112");
reportListView.setAdapter(reportAdpater);
reportAdpater.notifyDataSetChanged();
//report list view
lawfirmAdpater = new CallReportListViewAdapter();
lawfirmListView = (ListView) v.findViewById(R.id.lawfirmListView);
lawfirmListView.setAdapter(lawfirmAdpater);
lawfirmAdpater.addItem("법무법인 굳센 (24시)", "02-598-8284");
lawfirmListView.setAdapter(lawfirmAdpater);
lawfirmAdpater.notifyDataSetChanged();
setListViewHeightBasedOnChildren(reportListView);
setListViewHeightBasedOnChildren(lawfirmListView);
return v;
}
}
참고자료
반응형
'Study > Android' 카테고리의 다른 글
[Android | JAVA] 안드로이드 타이틀바, 상태바 색깔 바꾸기 (0) | 2021.08.30 |
---|---|
[Android | JAVA] List View (0) | 2021.08.29 |
[Android] Bottom Navigation Bar 모음 (0) | 2021.08.28 |
댓글