|
6 | 6 | import android.graphics.Color;
|
7 | 7 | import android.graphics.Typeface;
|
8 | 8 | import android.graphics.drawable.ColorDrawable;
|
| 9 | +import android.text.TextUtils; |
9 | 10 | import android.util.DisplayMetrics;
|
10 | 11 | import android.util.Log;
|
11 | 12 | import android.util.TypedValue;
|
@@ -53,6 +54,7 @@ public interface FileSelectCallback {
|
53 | 54 | private TextView titleView;
|
54 | 55 | private LinearLayout buttonLayout;
|
55 | 56 | private LinearLayout rootLayout;
|
| 57 | + private int paddingTb=12; |
56 | 58 |
|
57 | 59 | private float widthRatio = 1f;
|
58 | 60 | private float heightRatio = 1f;
|
@@ -226,32 +228,37 @@ private void adjustDialogHeight() {
|
226 | 228 | lp.width = (int) (metrics.widthPixels * widthRatio);
|
227 | 229 |
|
228 | 230 | int listViewHeight = calculateListViewHeight();
|
| 231 | + Log.d(TAG, "adjustDialogHeight: listViewHeight>>"+listViewHeight); |
229 | 232 | int dialogExtraHeight = calculateDialogExtraHeight();
|
| 233 | + Log.d(TAG, "adjustDialogHeight: dialogExtraHeight>>"+dialogExtraHeight); |
230 | 234 | int actualContentHeight = listViewHeight + dialogExtraHeight;
|
| 235 | + Log.d(TAG, "adjustDialogHeight: actualContentHeight>>"+actualContentHeight); |
231 | 236 | int maxHeight = (int) (metrics.heightPixels * heightRatio);
|
232 |
| - |
| 237 | + Log.d(TAG, "adjustDialogHeight: maxHeight>>"+maxHeight); |
233 | 238 | lp.height = Math.min(actualContentHeight, maxHeight);
|
234 | 239 | window.setAttributes(lp);
|
235 | 240 | }
|
236 | 241 | }
|
237 | 242 |
|
238 | 243 | private int calculateListViewHeight() {
|
239 |
| - if (adapter == null || adapter.getCount() == 0) return 0; |
240 |
| - |
| 244 | + int adaCount=adapter.getCount(); |
| 245 | + if (adapter == null || adaCount == 0) return 0; |
| 246 | + Log.d(TAG, "calculateListViewHeight: adapter.getCount()>>"+adaCount+",fileCount>>"+fileList.size()); |
241 | 247 | int totalHeight = 0;
|
242 |
| - for (int i = 0; i < adapter.getCount(); i++) { |
| 248 | + for (int i = 0; i < adaCount; i++) { |
243 | 249 | View item = adapter.getView(i, null, listView);
|
244 | 250 | item.measure(
|
245 | 251 | View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
|
246 | 252 | View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
|
| 253 | + Log.d(TAG, "calculateListViewHeight: getMeasuredHeight>>"+item.getMeasuredHeight()); |
247 | 254 | totalHeight += item.getMeasuredHeight();
|
248 | 255 | }
|
249 | 256 |
|
250 |
| - if (adapter.getCount() > 1) { |
251 |
| - totalHeight += (adapter.getCount() - 1) * listView.getDividerHeight(); |
| 257 | + if (adaCount > 1) { |
| 258 | + totalHeight += (adaCount - 1) * listView.getDividerHeight(); |
252 | 259 | }
|
253 | 260 |
|
254 |
| - return totalHeight; |
| 261 | + return totalHeight+paddingTb*2; |
255 | 262 | }
|
256 | 263 |
|
257 | 264 | private int calculateDialogExtraHeight() {
|
@@ -300,10 +307,13 @@ public View getView(int position, View convertView, ViewGroup parent) {
|
300 | 307 | File file = fileList.get(position);
|
301 | 308 | LinearLayout layout = new LinearLayout(context);
|
302 | 309 | layout.setOrientation(LinearLayout.HORIZONTAL);
|
303 |
| - layout.setPadding(22, 12, 22, 12); |
| 310 | + layout.setPadding(22, paddingTb, 22, paddingTb); |
304 | 311 | layout.setGravity(Gravity.CENTER_VERTICAL);
|
305 | 312 |
|
306 | 313 | TextView nameView = new TextView(context);
|
| 314 | + nameView.setSelected(true); // 关键点:触发 marquee 效果 |
| 315 | + nameView.setSingleLine(true); |
| 316 | + nameView.setEllipsize(TextUtils.TruncateAt.MARQUEE); |
307 | 317 | nameView.setTextSize(TypedValue.COMPLEX_UNIT_SP, itemTvSize);
|
308 | 318 | nameView.setLayoutParams(new LinearLayout.LayoutParams(
|
309 | 319 | 0, ViewGroup.LayoutParams.WRAP_CONTENT, 1));
|
|
0 commit comments