質問編集履歴
1
ソースコードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -21,4 +21,235 @@
|
|
21
21
|
画像2(作成したいLayoutイメージ)
|
22
22
|
|
23
23
|
インスタグラム風なUIを作りたいと思っています。
|
24
|
-
初心者の質問になりますが、ご存知の方がおりましたら、どうぞお教え下さい。
|
24
|
+
初心者の質問になりますが、ご存知の方がおりましたら、どうぞお教え下さい。
|
25
|
+
|
26
|
+
---
|
27
|
+
追記 - 20151018
|
28
|
+
|
29
|
+
- Activity_CommunicationSpace_MemberList
|
30
|
+
```java
|
31
|
+
public class Activity_CommunicationSpace_MemberList extends Activity {
|
32
|
+
|
33
|
+
private List<Data_User> objects = new ArrayList<Data_User>();
|
34
|
+
private Data_User item = new Data_User();
|
35
|
+
private String user_name;
|
36
|
+
private Bitmap user_icon;
|
37
|
+
private Bitmap user_profile;
|
38
|
+
|
39
|
+
@Override
|
40
|
+
public void onCreate(Bundle savedInstanceState) {
|
41
|
+
super.onCreate(savedInstanceState);
|
42
|
+
setContentView(R.layout.activity_communicationspace_memberlist);
|
43
|
+
|
44
|
+
user_name = "Test_Test";
|
45
|
+
user_icon = BitmapFactory.decodeResource(getResources(), R.drawable.icon_lamborghini);
|
46
|
+
|
47
|
+
for (int i = 0; i < 20; i++) {
|
48
|
+
item = new Data_User();
|
49
|
+
item.setNameData(user_name);
|
50
|
+
item.setIconData(user_icon);
|
51
|
+
objects.add(item);
|
52
|
+
}
|
53
|
+
|
54
|
+
Adapter_CommunicationSpace_MemberList adapter = new Adapter_CommunicationSpace_MemberList(getApplicationContext(), R.layout.adapter_communicationspace_memberlist, objects);
|
55
|
+
ExpandableHeightGridView expandableHeightGridView = (ExpandableHeightGridView) findViewById(R.id.gridview_communicationspace_memberlist);
|
56
|
+
expandableHeightGridView.setExpanded(true);
|
57
|
+
expandableHeightGridView.setAdapter(adapter);
|
58
|
+
|
59
|
+
final ScrollView scrollView = (ScrollView) findViewById(R.id.activity_communicationspace_memberlist_scrollView);
|
60
|
+
scrollView.post(new Runnable() {
|
61
|
+
public void run() {
|
62
|
+
scrollView.fullScroll(ScrollView.FOCUS_UP);
|
63
|
+
}
|
64
|
+
});
|
65
|
+
}
|
66
|
+
}
|
67
|
+
```
|
68
|
+
- Adapter_CommunicationSpace_MemberList
|
69
|
+
```java
|
70
|
+
public class Adapter_CommunicationSpace_MemberList extends ArrayAdapter<Data_User> {
|
71
|
+
private LayoutInflater layoutInflater_;
|
72
|
+
|
73
|
+
public Adapter_CommunicationSpace_MemberList(Context context, int textViewResourceId, List<Data_User> objects) {
|
74
|
+
super(context, textViewResourceId, objects);
|
75
|
+
layoutInflater_ = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
76
|
+
}
|
77
|
+
|
78
|
+
@Override
|
79
|
+
public View getView(int position, View convertView, ViewGroup parent) {
|
80
|
+
|
81
|
+
// 特定の行(position)のデータを得る
|
82
|
+
Data_User item = (Data_User) getItem(position);
|
83
|
+
|
84
|
+
// convertViewは使い回しされている可能性があるのでnullの時だけ新しく作る
|
85
|
+
if (null == convertView) {
|
86
|
+
convertView = layoutInflater_.inflate(R.layout.adapter_communicationspace_memberlist, null);
|
87
|
+
}
|
88
|
+
|
89
|
+
// Data_Adapter_ListViewのデータをViewの各Widgetにセットする
|
90
|
+
TextView textView;
|
91
|
+
textView = (TextView) convertView.findViewById(R.id.textview);
|
92
|
+
textView.setText(item.getNameData());
|
93
|
+
|
94
|
+
ImageView imageView;
|
95
|
+
imageView = (ImageView) convertView.findViewById(R.id.imageview);
|
96
|
+
imageView.setImageBitmap(item.getIconData());
|
97
|
+
|
98
|
+
return convertView;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
```
|
102
|
+
- Data_User
|
103
|
+
```java
|
104
|
+
public class Data_User {
|
105
|
+
private Bitmap iconData;
|
106
|
+
private String profileData;
|
107
|
+
private String nameData;
|
108
|
+
|
109
|
+
public void setIconData(Bitmap icon) {
|
110
|
+
iconData = icon;
|
111
|
+
}
|
112
|
+
|
113
|
+
public Bitmap getIconData() {
|
114
|
+
return iconData;
|
115
|
+
}
|
116
|
+
|
117
|
+
public void setProfileData(String profile) {
|
118
|
+
profileData = profile;
|
119
|
+
}
|
120
|
+
|
121
|
+
public String getProfileData() {
|
122
|
+
return profileData;
|
123
|
+
}
|
124
|
+
|
125
|
+
public void setNameData(String nameData){
|
126
|
+
this.nameData = nameData;
|
127
|
+
}
|
128
|
+
|
129
|
+
public String getNameData(){
|
130
|
+
return this.nameData;
|
131
|
+
|
132
|
+
}
|
133
|
+
}
|
134
|
+
```
|
135
|
+
- ExpandableHeightGridView
|
136
|
+
```java
|
137
|
+
/**
|
138
|
+
* ScrollView内でGridViewを使うためのクラス
|
139
|
+
*/
|
140
|
+
public class ExpandableHeightGridView extends GridView {
|
141
|
+
|
142
|
+
boolean expanded = false;
|
143
|
+
|
144
|
+
public ExpandableHeightGridView(Context context)
|
145
|
+
{
|
146
|
+
super(context);
|
147
|
+
}
|
148
|
+
|
149
|
+
public ExpandableHeightGridView(Context context, AttributeSet attrs)
|
150
|
+
{
|
151
|
+
super(context, attrs);
|
152
|
+
}
|
153
|
+
|
154
|
+
public ExpandableHeightGridView(Context context, AttributeSet attrs, int defStyle)
|
155
|
+
{
|
156
|
+
super(context, attrs, defStyle);
|
157
|
+
}
|
158
|
+
|
159
|
+
public boolean isExpanded()
|
160
|
+
{
|
161
|
+
return expanded;
|
162
|
+
}
|
163
|
+
|
164
|
+
@Override
|
165
|
+
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
166
|
+
{
|
167
|
+
// HACK! TAKE THAT ANDROID!
|
168
|
+
if (isExpanded())
|
169
|
+
{
|
170
|
+
// Calculate entire height by providing a very large height hint.
|
171
|
+
// View.MEASURED_SIZE_MASK represents the largest height possible.
|
172
|
+
int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, MeasureSpec.AT_MOST);
|
173
|
+
super.onMeasure(widthMeasureSpec, expandSpec);
|
174
|
+
|
175
|
+
ViewGroup.LayoutParams params = getLayoutParams();
|
176
|
+
params.height = getMeasuredHeight();
|
177
|
+
}
|
178
|
+
else
|
179
|
+
{
|
180
|
+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
181
|
+
}
|
182
|
+
}
|
183
|
+
|
184
|
+
public void setExpanded(boolean expanded)
|
185
|
+
{
|
186
|
+
this.expanded = expanded;
|
187
|
+
}
|
188
|
+
}
|
189
|
+
```
|
190
|
+
- activity_communicationspace_memberlist
|
191
|
+
```xml
|
192
|
+
<?xml version="1.0" encoding="utf-8"?>
|
193
|
+
<RelativeLayout android:id="@+id/relativelayout1"
|
194
|
+
xmlns:android="http://schemas.android.com/apk/res/android"
|
195
|
+
xmlns:tools="http://schemas.android.com/tools"
|
196
|
+
android:layout_width="match_parent"
|
197
|
+
android:layout_height="match_parent"
|
198
|
+
android:layout_marginTop="10dp"
|
199
|
+
android:layout_marginBottom="5dp"
|
200
|
+
android:layout_marginRight="10dp"
|
201
|
+
android:layout_marginLeft="10dp"
|
202
|
+
android:orientation="vertical"
|
203
|
+
tools:context="packagename.Activity_CommunicationSpace_MemberList" >
|
204
|
+
<ScrollView android:id="@+id/activity_communicationspace_memberlist_scrollView"
|
205
|
+
android:layout_width="match_parent"
|
206
|
+
android:layout_height="match_parent">
|
207
|
+
<LinearLayout
|
208
|
+
android:layout_width="match_parent"
|
209
|
+
android:layout_height="match_parent"
|
210
|
+
android:orientation="vertical" >
|
211
|
+
<LinearLayout
|
212
|
+
android:layout_width="match_parent"
|
213
|
+
android:layout_height="wrap_content"
|
214
|
+
android:orientation="vertical"
|
215
|
+
android:background="#FFFFFF" >
|
216
|
+
<TextViewなどのwidget
|
217
|
+
.
|
218
|
+
.
|
219
|
+
.
|
220
|
+
.
|
221
|
+
</LinearLayout>
|
222
|
+
<LinearLayout
|
223
|
+
android:layout_width="wrap_content"
|
224
|
+
android:layout_height="wrap_content"
|
225
|
+
android:orientation="vertical"
|
226
|
+
android:paddingTop="3dp" >
|
227
|
+
<packagename.ExpandableHeightGridView android:id="@+id/gridview_communicationspace_memberlist"
|
228
|
+
android:layout_width="wrap_content"
|
229
|
+
android:layout_height="wrap_content"
|
230
|
+
android:numColumns="4"/>
|
231
|
+
<!--android:gravity="center"-->
|
232
|
+
<!--android:minHeight="100dp"-->
|
233
|
+
<!--android:stretchMode="columnWidth"-->
|
234
|
+
</LinearLayout>
|
235
|
+
</LinearLayout>
|
236
|
+
</ScrollView>
|
237
|
+
</RelativeLayout>
|
238
|
+
```
|
239
|
+
- adapter_communicationspace_memberlist
|
240
|
+
```xml
|
241
|
+
<?xml version="1.0" encoding="utf-8"?>
|
242
|
+
<FrameLayout
|
243
|
+
xmlns:android="http://schemas.android.com/apk/res/android"
|
244
|
+
android:layout_width="wrap_content"
|
245
|
+
android:layout_height="wrap_content">
|
246
|
+
<ImageView android:id="@+id/imageview"
|
247
|
+
android:layout_width="wrap_content"
|
248
|
+
android:layout_height="wrap_content"
|
249
|
+
android:src="@drawable/icon_lamborghini"/>
|
250
|
+
<TextView android:id="@+id/textview"
|
251
|
+
android:layout_width="wrap_content"
|
252
|
+
android:layout_height="wrap_content"
|
253
|
+
android:text="test"/>
|
254
|
+
</FrameLayout>
|
255
|
+
```
|