diff --git a/app/src/main/java/club/hifriends/activity/LookInfoActivity.java b/app/src/main/java/club/hifriends/activity/LookInfoActivity.java index ef823ac..327abca 100644 --- a/app/src/main/java/club/hifriends/activity/LookInfoActivity.java +++ b/app/src/main/java/club/hifriends/activity/LookInfoActivity.java @@ -108,6 +108,9 @@ public void onResponse(String response) { tv_content.setText(activityInfo.getContent()); liv_partner.setAdapter(new UserListAdapter(getBaseContext(), R.layout.listview_activity_info_item, activityInfo.getPartnerArrayList())); + + //根据listview的item数目和高度设置本身的高度,以保证listview能全部展开展示 + UserListAdapter.setListViewHeightBasedOnChildren(liv_partner); } else if (json_res.getInt("code") == 404) { Toast.makeText(getBaseContext(),"该活动不存在或者已被删除",Toast.LENGTH_SHORT).show(); onBackPressed(); diff --git a/app/src/main/java/club/hifriends/activity/adapter/UserListAdapter.java b/app/src/main/java/club/hifriends/activity/adapter/UserListAdapter.java index 8b9dfed..87f2f35 100644 --- a/app/src/main/java/club/hifriends/activity/adapter/UserListAdapter.java +++ b/app/src/main/java/club/hifriends/activity/adapter/UserListAdapter.java @@ -9,6 +9,8 @@ import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; +import android.widget.ListAdapter; +import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; @@ -50,4 +52,26 @@ public void onClick(View v) { }); return view; } + + public static void setListViewHeightBasedOnChildren(ListView listView) { + //根据listview的item数目设置宽度 + 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); + } + + } diff --git a/app/src/main/java/club/hifriends/activity/beans/ActivityInfo.java b/app/src/main/java/club/hifriends/activity/beans/ActivityInfo.java index ec42570..23ec16e 100644 --- a/app/src/main/java/club/hifriends/activity/beans/ActivityInfo.java +++ b/app/src/main/java/club/hifriends/activity/beans/ActivityInfo.java @@ -24,11 +24,11 @@ public ActivityInfo (JSONObject response)throws JSONException{ this.activity_id = response.getString("activity_id"); this.title = response.getString("title"); this.content = response.getString("content"); - partnerArrayList = new ArrayList<>(); + this.partnerArrayList = new ArrayList<>(); JSONArray partners = response.getJSONArray("partners"); for(int i = 0;i