Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

에이치의 모바일 앱 개발

ListView Hegiht Setting version 1.0.1 본문

Android/Android 개발 소스

ListView Hegiht Setting version 1.0.1

로이누리 2017. 12. 23. 01:47

/**

* Created by lsh on 2016-08-17.

* 리스트 뷰 높이 지정
* version 1.0.1
* @param adapter
* @param listview
* @return
*/
private ViewGroup.LayoutParams listviewParams(CustomAdapter adapter, ListView listview) {
int totalHeight = 0;
for (int i = 0; i < adapter.getCount(); i++) {
View listItem = adapter.getView(i, null, listview);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams viewparams = listview.getLayoutParams();

viewparams.height = totalHeight + (listview.getDividerHeight() * (adapter.getCount() - 1));
((ViewGroup.MarginLayoutParams) viewparams).setMargins(10, 10, 10, 10); // Can be deleted
return viewparams;
} ListView saveFileListView = (ListView) findViewById(R.id.saveFileListView); ArrayAdapter wifiContentAdapter = new ArrayAdapter<String>(context, R.layout.font_listview, content); saveFileListView.setLayoutParams(listViewParams); saveFileListView.setAdapter(wifiContentAdapter);



xml 부분

<LinearLayout
android:id="@+id/layout_listviewA_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ListView
android:id="@+id/listview_listA"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ffffff"
android:divider="#b8b7b7"
android:dividerHeight="0.1dip"
android:scaleType="centerCrop" />

</LinearLayout>
</ScrollView>
</LinearLayout>

 

Comments