質問編集履歴

1

ソースコードの追加

2016/01/18 06:06

投稿

n_kazuki
n_kazuki

スコア25

test CHANGED
File without changes
test CHANGED
@@ -45,3 +45,465 @@
45
45
  インスタグラム風なUIを作りたいと思っています。
46
46
 
47
47
  初心者の質問になりますが、ご存知の方がおりましたら、どうぞお教え下さい。
48
+
49
+
50
+
51
+ ---
52
+
53
+ 追記 - 20151018
54
+
55
+
56
+
57
+ - Activity_CommunicationSpace_MemberList
58
+
59
+ ```java
60
+
61
+ public class Activity_CommunicationSpace_MemberList extends Activity {
62
+
63
+
64
+
65
+ private List<Data_User> objects = new ArrayList<Data_User>();
66
+
67
+ private Data_User item = new Data_User();
68
+
69
+ private String user_name;
70
+
71
+ private Bitmap user_icon;
72
+
73
+ private Bitmap user_profile;
74
+
75
+
76
+
77
+ @Override
78
+
79
+ public void onCreate(Bundle savedInstanceState) {
80
+
81
+ super.onCreate(savedInstanceState);
82
+
83
+ setContentView(R.layout.activity_communicationspace_memberlist);
84
+
85
+
86
+
87
+ user_name = "Test_Test";
88
+
89
+ user_icon = BitmapFactory.decodeResource(getResources(), R.drawable.icon_lamborghini);
90
+
91
+
92
+
93
+ for (int i = 0; i < 20; i++) {
94
+
95
+ item = new Data_User();
96
+
97
+ item.setNameData(user_name);
98
+
99
+ item.setIconData(user_icon);
100
+
101
+ objects.add(item);
102
+
103
+ }
104
+
105
+
106
+
107
+ Adapter_CommunicationSpace_MemberList adapter = new Adapter_CommunicationSpace_MemberList(getApplicationContext(), R.layout.adapter_communicationspace_memberlist, objects);
108
+
109
+ ExpandableHeightGridView expandableHeightGridView = (ExpandableHeightGridView) findViewById(R.id.gridview_communicationspace_memberlist);
110
+
111
+ expandableHeightGridView.setExpanded(true);
112
+
113
+ expandableHeightGridView.setAdapter(adapter);
114
+
115
+
116
+
117
+ final ScrollView scrollView = (ScrollView) findViewById(R.id.activity_communicationspace_memberlist_scrollView);
118
+
119
+ scrollView.post(new Runnable() {
120
+
121
+ public void run() {
122
+
123
+ scrollView.fullScroll(ScrollView.FOCUS_UP);
124
+
125
+ }
126
+
127
+ });
128
+
129
+ }
130
+
131
+ }
132
+
133
+ ```
134
+
135
+ - Adapter_CommunicationSpace_MemberList
136
+
137
+ ```java
138
+
139
+ public class Adapter_CommunicationSpace_MemberList extends ArrayAdapter<Data_User> {
140
+
141
+ private LayoutInflater layoutInflater_;
142
+
143
+
144
+
145
+ public Adapter_CommunicationSpace_MemberList(Context context, int textViewResourceId, List<Data_User> objects) {
146
+
147
+ super(context, textViewResourceId, objects);
148
+
149
+ layoutInflater_ = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
150
+
151
+ }
152
+
153
+
154
+
155
+ @Override
156
+
157
+ public View getView(int position, View convertView, ViewGroup parent) {
158
+
159
+
160
+
161
+ // 特定の行(position)のデータを得る
162
+
163
+ Data_User item = (Data_User) getItem(position);
164
+
165
+
166
+
167
+ // convertViewは使い回しされている可能性があるのでnullの時だけ新しく作る
168
+
169
+ if (null == convertView) {
170
+
171
+ convertView = layoutInflater_.inflate(R.layout.adapter_communicationspace_memberlist, null);
172
+
173
+ }
174
+
175
+
176
+
177
+ // Data_Adapter_ListViewのデータをViewの各Widgetにセットする
178
+
179
+ TextView textView;
180
+
181
+ textView = (TextView) convertView.findViewById(R.id.textview);
182
+
183
+ textView.setText(item.getNameData());
184
+
185
+
186
+
187
+ ImageView imageView;
188
+
189
+ imageView = (ImageView) convertView.findViewById(R.id.imageview);
190
+
191
+ imageView.setImageBitmap(item.getIconData());
192
+
193
+
194
+
195
+ return convertView;
196
+
197
+ }
198
+
199
+ }
200
+
201
+ ```
202
+
203
+ - Data_User
204
+
205
+ ```java
206
+
207
+ public class Data_User {
208
+
209
+ private Bitmap iconData;
210
+
211
+ private String profileData;
212
+
213
+ private String nameData;
214
+
215
+
216
+
217
+ public void setIconData(Bitmap icon) {
218
+
219
+ iconData = icon;
220
+
221
+ }
222
+
223
+
224
+
225
+ public Bitmap getIconData() {
226
+
227
+ return iconData;
228
+
229
+ }
230
+
231
+
232
+
233
+ public void setProfileData(String profile) {
234
+
235
+ profileData = profile;
236
+
237
+ }
238
+
239
+
240
+
241
+ public String getProfileData() {
242
+
243
+ return profileData;
244
+
245
+ }
246
+
247
+
248
+
249
+ public void setNameData(String nameData){
250
+
251
+ this.nameData = nameData;
252
+
253
+ }
254
+
255
+
256
+
257
+ public String getNameData(){
258
+
259
+ return this.nameData;
260
+
261
+
262
+
263
+ }
264
+
265
+ }
266
+
267
+ ```
268
+
269
+ - ExpandableHeightGridView
270
+
271
+ ```java
272
+
273
+ /**
274
+
275
+ * ScrollView内でGridViewを使うためのクラス
276
+
277
+ */
278
+
279
+ public class ExpandableHeightGridView extends GridView {
280
+
281
+
282
+
283
+ boolean expanded = false;
284
+
285
+
286
+
287
+ public ExpandableHeightGridView(Context context)
288
+
289
+ {
290
+
291
+ super(context);
292
+
293
+ }
294
+
295
+
296
+
297
+ public ExpandableHeightGridView(Context context, AttributeSet attrs)
298
+
299
+ {
300
+
301
+ super(context, attrs);
302
+
303
+ }
304
+
305
+
306
+
307
+ public ExpandableHeightGridView(Context context, AttributeSet attrs, int defStyle)
308
+
309
+ {
310
+
311
+ super(context, attrs, defStyle);
312
+
313
+ }
314
+
315
+
316
+
317
+ public boolean isExpanded()
318
+
319
+ {
320
+
321
+ return expanded;
322
+
323
+ }
324
+
325
+
326
+
327
+ @Override
328
+
329
+ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
330
+
331
+ {
332
+
333
+ // HACK! TAKE THAT ANDROID!
334
+
335
+ if (isExpanded())
336
+
337
+ {
338
+
339
+ // Calculate entire height by providing a very large height hint.
340
+
341
+ // View.MEASURED_SIZE_MASK represents the largest height possible.
342
+
343
+ int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, MeasureSpec.AT_MOST);
344
+
345
+ super.onMeasure(widthMeasureSpec, expandSpec);
346
+
347
+
348
+
349
+ ViewGroup.LayoutParams params = getLayoutParams();
350
+
351
+ params.height = getMeasuredHeight();
352
+
353
+ }
354
+
355
+ else
356
+
357
+ {
358
+
359
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
360
+
361
+ }
362
+
363
+ }
364
+
365
+
366
+
367
+ public void setExpanded(boolean expanded)
368
+
369
+ {
370
+
371
+ this.expanded = expanded;
372
+
373
+ }
374
+
375
+ }
376
+
377
+ ```
378
+
379
+ - activity_communicationspace_memberlist
380
+
381
+ ```xml
382
+
383
+ <?xml version="1.0" encoding="utf-8"?>
384
+
385
+ <RelativeLayout android:id="@+id/relativelayout1"
386
+
387
+ xmlns:android="http://schemas.android.com/apk/res/android"
388
+
389
+ xmlns:tools="http://schemas.android.com/tools"
390
+
391
+ android:layout_width="match_parent"
392
+
393
+ android:layout_height="match_parent"
394
+
395
+ android:layout_marginTop="10dp"
396
+
397
+ android:layout_marginBottom="5dp"
398
+
399
+ android:layout_marginRight="10dp"
400
+
401
+ android:layout_marginLeft="10dp"
402
+
403
+ android:orientation="vertical"
404
+
405
+ tools:context="packagename.Activity_CommunicationSpace_MemberList" >
406
+
407
+ <ScrollView android:id="@+id/activity_communicationspace_memberlist_scrollView"
408
+
409
+ android:layout_width="match_parent"
410
+
411
+ android:layout_height="match_parent">
412
+
413
+ <LinearLayout
414
+
415
+ android:layout_width="match_parent"
416
+
417
+ android:layout_height="match_parent"
418
+
419
+ android:orientation="vertical" >
420
+
421
+ <LinearLayout
422
+
423
+ android:layout_width="match_parent"
424
+
425
+ android:layout_height="wrap_content"
426
+
427
+ android:orientation="vertical"
428
+
429
+ android:background="#FFFFFF" >
430
+
431
+ <TextViewなどのwidget
432
+
433
+ .
434
+
435
+ .
436
+
437
+ .
438
+
439
+ .
440
+
441
+ </LinearLayout>
442
+
443
+ <LinearLayout
444
+
445
+ android:layout_width="wrap_content"
446
+
447
+ android:layout_height="wrap_content"
448
+
449
+ android:orientation="vertical"
450
+
451
+ android:paddingTop="3dp" >
452
+
453
+ <packagename.ExpandableHeightGridView android:id="@+id/gridview_communicationspace_memberlist"
454
+
455
+ android:layout_width="wrap_content"
456
+
457
+ android:layout_height="wrap_content"
458
+
459
+ android:numColumns="4"/>
460
+
461
+ <!--android:gravity="center"-->
462
+
463
+ <!--android:minHeight="100dp"-->
464
+
465
+ <!--android:stretchMode="columnWidth"-->
466
+
467
+ </LinearLayout>
468
+
469
+ </LinearLayout>
470
+
471
+ </ScrollView>
472
+
473
+ </RelativeLayout>
474
+
475
+ ```
476
+
477
+ - adapter_communicationspace_memberlist
478
+
479
+ ```xml
480
+
481
+ <?xml version="1.0" encoding="utf-8"?>
482
+
483
+ <FrameLayout
484
+
485
+ xmlns:android="http://schemas.android.com/apk/res/android"
486
+
487
+ android:layout_width="wrap_content"
488
+
489
+ android:layout_height="wrap_content">
490
+
491
+ <ImageView android:id="@+id/imageview"
492
+
493
+ android:layout_width="wrap_content"
494
+
495
+ android:layout_height="wrap_content"
496
+
497
+ android:src="@drawable/icon_lamborghini"/>
498
+
499
+ <TextView android:id="@+id/textview"
500
+
501
+ android:layout_width="wrap_content"
502
+
503
+ android:layout_height="wrap_content"
504
+
505
+ android:text="test"/>
506
+
507
+ </FrameLayout>
508
+
509
+ ```