problem ScrollView

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

problem ScrollView

Postby The_One_Neo » Wed Apr 15, 2009 9:09 am

i have a problem about ScrollView

i want add myView(extends View) to the ScrollView, myView i will draw something, image or text,
but when i create myView and add it in the scrollView ,but get the Height = 0 onSizeChanged(), i don't know why?

(1) myActivity
final LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT));


LinearLayout.LayoutParams paramS = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,1);
scroll = new ScrollView(this);
ViewGroup.LayoutParams paramSvLp = new ScrollView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
scroll.setLayoutParams(paramS);
layout.addView(scroll);

history = new HistoryTextView(this);
history.setLayoutParams(paramSvLp);
scroll.addView(history);

(2) HistoryTextView

public class HistoryTextView extends LinearLayout{
private Activity activity;
private EmotionTextView topText;

public HistoryTextView(Context context){
super(context);
activity = (Activity) context;
setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
setOrientation(LinearLayout.VERTICAL);
setGravity(Gravity.FILL);
addItem(str);
}

public void addItem(String str)
{
LayoutParams params1 = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT);
EmotionTextView etv1 = new EmotionTextView(getContext(), null);
String show1=" 12345678 :) ";

etv1.setLayoutParams(params1);
// etv1.invalidate();
addView(etv1);
etv1.setShowText(show1);
}
}


(3) EmotionTextView

public class EmotionTextView extends View{
public String showText;
public Paint paint;
public EmotionTextView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub


//setFocusable(true);
paint = new Paint();
paint.setTextSize(20);
paint.setColor(Color.BLUE);
paint.setAntiAlias(true);
}

public void setShowText(String showText)
{
this.showText=showText;

}


protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
width=w; //w = 0???
init();
}



@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(0xfff00fff);
}
The_One_Neo
Developer
Developer
 
Posts: 28
Joined: Wed May 07, 2008 9:34 am

Top

Re: problem ScrollView

Postby The_One_Neo » Wed Apr 15, 2009 9:49 am

i think may be this EmotionTextView is my own View ,so the system can't get the height,
i need set determinate height for it ???
The_One_Neo
Developer
Developer
 
Posts: 28
Joined: Wed May 07, 2008 9:34 am

Postby WarrenFaith » Wed Apr 15, 2009 10:41 am

Two things:
1. please use the highlight tags (the buttons labeled with .java and .xml)
2. afaik do you know the answer because you posted it once: http://www.anddev.org/access_xml_attrib ... t5658.html
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby The_One_Neo » Wed Apr 15, 2009 11:12 am

(1) i means, i will add EmotionTextView in the scroll, but this view is own, i will set long str or short str int the view.
may be the str used 100 pix or 50pix i don't know, before create the view, if i used the

LayoutParams params1 = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT);

create EmotionTextView and start
but in the EmotionTextView onSizeChanged(), return the height zero

EmotionTextView etv1 = new EmotionTextView(getContext(), null);
etv1.setLayoutParams(params1);

may be own view must set the size in the LayoutParams


(2) you can get the flow from the debug task.
before onSizeChanged() you can't get the size of the TextView. because system will auto fit
The_One_Neo
Developer
Developer
 
Posts: 28
Joined: Wed May 07, 2008 9:34 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests