I customized a ViewGroup, for processing in a row if there are multiple rows of less than Button, the wrap, if I do not put ScrollView is to run, but sometimes change the number of trekking too much, I want to put ScrollView do scroll down, but after I put ScrollView, will not show ViewGroup components, and seek solutions, thank you!
package com.android.picker;
import java.util.List;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class MyViewGroup extends ViewGroup {
private final static String TAG = "MyViewGroup";
public final static int VIEW_MARGIN = 2;
private final static int MAX_TAG_LINES = 3;
private Button lastMoreButton;
public int totalHeight = 0;
public MyViewGroup (Context context) {
super (context);
Log.i (TAG, "myViewgroup");
}
public void fullTags (Context context, Listrs, Button button) {
for (String s: rs) {
Button v = new Button (context);
v.setText (s);
this.addView (v);
};
if (button! = null) {
this.addView (button);
this.lastMoreButton = button;
}
}
public void fullTags (Context context, Listrs) {
this.fullTags (context, rs, null);
}
public MyViewGroup (Context context, AttributeSet attributeSet) {
super (context, attributeSet);
Log.i (TAG, "myViewgroupattributeSet");
}
@ Override
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
Log.d (TAG, "widthMeasureSpec =" + widthMeasureSpec + "heightMeasureSpec" + heightMeasureSpec);
for (int index = 0; indexfinal View child = getChildAt (index);
/ / Measure
child.measure (MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
totalHeight + = child.getMeasuredHeight ();
}
super.onMeasure (widthMeasureSpec, heightMeasureSpec);
}
@ Override
protected void onLayout (boolean arg0, int l, int t, int r, int b) {
Log.d (TAG, "changed =" + arg0 + "left =" + l + "top =" + t + "right =" + r + "botom =" + b);
final int count = getChildCount ();
int row = 0 ;/ / which row lay you view relative to parent
int lengthX = l; / / right position of child relative to parent
int lengthY = t; / / bottom position of child relative to parent
for (int i = 0; ifinal View child = this.getChildAt (i);
Log.i ("aa", ((Button) child) getText () toString ()..);
int width = child.getMeasuredWidth ();
int height = child.getMeasuredHeight ();
lengthX + = width + VIEW_MARGIN;
/ / If it can't drawing on a same line, skip to next line
if (lengthX> r) {
lengthX = width + VIEW_MARGIN + l;
row + +;
}
lengthY = row * (height + VIEW_MARGIN) + VIEW_MARGIN + height + t;
child.layout (lengthX-width, lengthY-height, lengthX, lengthY);
}
}
}
android: layout_width = "fill_parent"
android: layout_height = "fill_parent"
android: orientation = "vertical">android: id = "@ + id / myalltags_scrollview"
android: layout_width = "fill_parent"
android: layout_height = "fill_parent"
android: scrollbars = "vertical">android: layout_width = "fill_parent"
android: layout_height = "fill_parent">
package com.android.picker;
import java.util.ArrayList;
import java.util.List;
import android.app.Dialog;
import android.content.Context;
import android.util.Log;
import android.view.ViewGroup;
public class MyTagsDialog extends Dialog {
private Context context;
private MyViewGroup myAllTagsView;
public MyTagsDialog (Context context) {
super (context);
this.context = context;
this.setContentView (R.layout.mytagslayout);
initView ();
initData ();
}
private void initData () {
Listrs = new ArrayList ();
rs.add ("base fee");
rs.add ("group of people to a person");
rs.add ("Lord have on relaxation");
rs.add ("Where a person put up by");
rs.add ("multi knew Xie");
rs.add ("I was a now");
rs.add ("Test 1");
rs.add ("Test 2");
rs.add ("Test 3");
rs.add ("Test 4");
rs.add ("Test 5");
rs.add ("Test 6");
myAllTagsView.fullTags (context, rs);
/ / MyViewGroupPackage mypackages = new MyViewGroupPackage ();
/ / Mypackages.hasmore = true;
/ / Mypackages.imems = rs;
/ / MyAllTagsView.fullTags (context, rs);
/ / ViewGroup.LayoutParams params = myAllTagsView.getLayoutParams ();
/ / Params.height = myAllTagsView.totalHeight + 100;
/ / Log.i ("cccc", "" + params.height);
/ / MyAllTagsView.setLayoutParams (params);
/ / UIHelper.setListViewHeightBasedOnChildren (trip_act_tripotherlistview, user_info_scrollview);
}
private void initView () {
myAllTagsView = (MyViewGroup) this.findViewById (R.id.myalltags);
}
}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Li unknown sleep ah.
But ScrollView inside view layout_height you should not wrap_content
Reply:
lz resolved yet? Can say how to do next
Reply:
Solved yet, seeking answers
No comments:
Post a Comment