package example.withoutxml;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class FrameExample extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
LinearLayout ll=new LinearLayout(this);
ll.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
ll.setOrientation(LinearLayout.VERTICAL);
ll.setBackgroundResource(R.drawable.bunch);
ll.setGravity(LinearLayout.VERTICAL);
FrameLayout fl=new FrameLayout(this);
fl.setLayoutParams(new FrameLayout.LayoutParams
(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT));
ImageView iv=new ImageView(this);
iv.setLayoutParams(new FrameLayout.LayoutParams
(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT));
iv.setPadding(30, 30, 30, 30);
iv.setImageResource(R.drawable.pinkrose);
fl.addView(iv);
TextView tv1=new TextView(this);
FrameLayout.LayoutParams params= new FrameLayout.LayoutParams
( LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
// tv1.setLayoutParams(new FrameLayout.LayoutParams
// (FrameLayout.LayoutParams.FILL_PARENT,
// FrameLayout.LayoutParams.WRAP_CONTENT));
tv1.setGravity(Gravity.TOP);
tv1.setText("this is upper part of image");
tv1.setTextColor(0xffff0000);
tv1.setTextSize(40);
tv1.setLayoutParams(params);
fl.addView(tv1);
TextView tv2=new TextView(this);
FrameLayout.LayoutParams params1= new FrameLayout.LayoutParams
( LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
// tv2.setLayoutParams(new FrameLayout.LayoutParams
// (FrameLayout.LayoutParams.FILL_PARENT,
// FrameLayout.LayoutParams.WRAP_CONTENT));
tv2.setLayoutParams(params1);
//tv2.setGravity(Gravity.BOTTOM);
tv2.setGravity(android.view.Gravity.BOTTOM);
tv2.setText("this is lower part of image");
tv2.setTextColor(0xff00ff00);
tv2.setTextSize(40);
fl.addView(tv2);
ll.addView(fl);
setContentView(ll);
}
}
This comment has been removed by the author.
ReplyDelete