Cannot implement linerGradient() in TextView inside onCreate() method - android

I want to implement linearGradient() in my textView. I want it in a way so that when the activity loads up, the linearGradient() gets applied on my textview. I was able to do it in a button click listener, but the linear gradient does not work whenever I implement it in the onCreate() method. Below is my xml layout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical" >
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textSize="70sp" />
<Button
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="63dp"
android:text="Apply Gradient Text" />
</RelativeLayout>
MainActivity.java file:
import android.app.Activity;
import android.graphics.Point;
import android.graphics.Shader;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener {
private TextView tv;
private Button btn;
private int mWidth;
private int mHeight;
private Shader shader;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView)findViewById(R.id.tv);
btn=(Button)findViewById(R.id.btn);
btn.setOnClickListener(this);
tv.setText(" Instagram ");
Typeface face=Typeface.createFromAsset(getAssets(), "fonts/billabong.ttf");
tv.setTypeface(face);
}
public void onClick(View view) {
mWidth=tv.getWidth();
mHeight=tv.getHeight();
Point size = new Point(mWidth,mHeight);
GradientManager gm= new GradientManager(getApplicationContext(),size);
shader=gm.getRandomLinearGradient();
tv.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
tv.getPaint().setShader(shader);
}
}
GradientManager.java file:
import android.content.Context;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Point;
import android.graphics.Shader;
public class GradientManager {
private Point mSize;
public GradientManager(Context context, Point size){
this.mSize = size;
}
protected LinearGradient getRandomLinearGradient(){
LinearGradient gradient = new LinearGradient(0, 0, mSize.x, mSize.y,
new int[] {Color.parseColor("#6656C8"), Color.parseColor("#8E33A9"),Color.parseColor("#BB328C"), Color.parseColor("#ED4B3E"),
Color.parseColor("#FA8031"), Color.parseColor("#FEC65C"), Color.parseColor("#FFD374") },null,
Shader.TileMode.MIRROR
);
return gradient;
}
}
Screenshot when activity starts:
Screenshot when I press the button:
What I want to implement is given below (I removed the button):
MainActivity.java file:
import android.app.Activity;
import android.graphics.Point;
import android.graphics.Shader;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView tv;
private int mWidth;
private int mHeight;
private Shader shader;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView)findViewById(R.id.tv);
tv.setText(" Instagram ");
Typeface face=Typeface.createFromAsset(getAssets(), "fonts/billabong.ttf");
tv.setTypeface(face);
mWidth=tv.getWidth();
mHeight=tv.getHeight();
Point size = new Point(mWidth,mHeight);
GradientManager gm= new GradientManager(getApplicationContext(),size);
shader=gm.getRandomLinearGradient();
tv.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
tv.getPaint().setShader(shader);
}
}
The contents of GradientManager.java is unchanged, Only the button is removed from my layout. The above code does not show any gradient color, instead It displays the whole textView with the first color of the linear gradient color parameter [Color.parseColor("#6656C8")]. This is my screenshot:
Can someone please help me with the code? What am I missing? Any help is appreciated.

You are using tv.getWidth and getHeight during onCreate. At that time TextView is not measured yet therefore those values are not valid. İf you have to get width and height for gradient you should apply your gradient after measure step is done(i.e. using ongloballayoutlistener).

Related

Programmatically setTextColor of widget on based on user input

I want to make a clock widget where in from its app user can set the textColor according to their wish.
So I want to change the TextClock's text color dynamically and programmatically on users click.
I tried using the simple setTextColor() method but there is no such method for setting text color of widget.
Below is the code I tried but it crashed the app on user click(touch).
I expect that the color of text changes on user's touch(that can be on any Button or ImageView).
package com.example.demowidget;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextClock;
public class MainActivity extends AppCompatActivity {
TextClock tctClock;
ImageView imgIcon;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imgIcon = findViewById(R.id.imgIcon);
tctClock = findViewById(R.id.tctClock);
imgIcon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
tctClock.getBackground().setColorFilter(Color.parseColor("#000000"), PorterDuff.Mode.SRC_ATOP);
}
});
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/widget_margin">
<TextClock
android:id="#+id/tctClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/widget_back"
android:fontFamily="#font/lato"
android:padding="10dp"
android:textColor="#11AB6B"
android:textSize="36sp" />
</RelativeLayout>
you can try for this..
first add you color in color.xml file
<color name="your_color">#094D92</color>
and replace this line--
tctClock.setTextColor(Color.parseColor("#094D92"));
to
tctClock.setTextColor(getResources().getColor(R.color.your_color))

Strange behavior with Android view.invalidate()

I have 3 custom views placed vertically in a LinearLayout, they are used to display different dynamic info, so they're supposed be invalidated and redrawn at different time. But I found the view invalidation is out of usual expectation, that is: if you invalidate the top view,all 3 views are invalidated at the same time, if you invalidate the middle view, the middle and bottom views are invalidated, the top one is not, if you invalidate the bottom view, only the bottom view itself is invalidated, this is what I want, so what happened with the first 2 cases ? I searched and got similar questions like:
https://stackoverflow.com/questions/26192491/invalidate-one-view-force-other-views-invalidate-too-how-separating-that
Android Invalidate() only single view
but it seems no exact answer. I post my code here, any comment is appreciated.
TestView.java
package com.vrb.myview;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
public class TestView extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onTest(View view){
MyView1 mv1 = (MyView1)findViewById(R.id.mv1);
MyView1 mv2 = (MyView1)findViewById(R.id.mv2);
MyView1 mv3 = (MyView1)findViewById(R.id.mv3);
mv1.invalidate(); // all 3 views are invalidated
// mv2.invalidate(); // mv2 and mv3 are invalidated
// mv3.invalidate(); // only mv3 is invalidated,this is what I want
}
}
MyView1.java
package com.vrb.myview;
import java.util.Random;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
public class MyView1 extends View {
Rect rc=null;
Paint p=null;
Random r;
public MyView1(Context ctx){
super(ctx);
rc = new Rect();
p = new Paint();
r = new Random();
}
public MyView1(Context ctx, AttributeSet set){
super(ctx, set);
rc = new Rect();
p = new Paint();
r = new Random();
}
public void onDraw(Canvas canvas){
if(canvas.getClipBounds(rc)){
Log.d("MyView1","id="+getId()+" Rect: "+rc.left+","+rc.top+","+rc.right+","+rc.bottom);
p.setColor(Color.argb(0xff, Math.abs(r.nextInt())%255, Math.abs(r.nextInt())%255, Math.abs(r.nextInt())%255));
canvas.drawRect(rc, p);
}else{
Log.d("MyView1","id="+getId()+" Rect=null");
}
}
}
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/root"
android:orientation="vertical"
tools:context="com.vrb.myview.TestView" >
<com.vrb.myview.MyView1
android:layout_width="match_parent"
android:layout_height="100px"
android:id="#+id/mv1" />
<com.vrb.myview.MyView1
android:layout_width="match_parent"
android:layout_height="100px"
android:id="#+id/mv2" />
<com.vrb.myview.MyView1
android:layout_width="match_parent"
android:layout_height="100px"
android:id="#+id/mv3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Invalidate"
android:onClick="onTest"
android:id="#+id/btn" />
</LinearLayout>
You shouldn't rely on the count or the time of the calls to onDraw() for the internal state of your View. Move the p.setColor() call to a separate public method, and call invalidate() at the end of it. For example:
public class MyView1 extends View {
...
public void changePaint() {
p.setColor(Color.argb(0xff, Math.abs(r.nextInt()) % 255, Math.abs(r.nextInt()) % 255, Math.abs(r.nextInt()) % 255));
invalidate();
}
}
Then in your onTest() method:
public void onTest(View view) {
MyView1 mv1 = (MyView1)findViewById(R.id.mv1);
...
mv1.changePaint();
...
}

setOnClickListener makes Force Close

When I launch the application and click the button to go to the Activity, I suddenly get a Force Close. I've tried to erase it all and write it again, but it is still there. What could be the problem?
package com.alexgascon.formuladora;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Matematicas extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
final Button BtnEcSegundoGrado = (Button)findViewById(R.id.ecsegundogrado);
final Button BtnFracciones = (Button)findViewById(R.id.fracciones);
final Button BtnMCD = (Button)findViewById(R.id.maximocomunBoton);
BtnMCD.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0) {
Intent MCDintent = new Intent(Matematicas.this,Maximocomun.class);
startActivity(MCDintent);
}
});
}
}
And here is the layout code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/pizarramatesverde"
android:gravity="center" >
<Button
android:id="#+id/ecsegundogrado"
android:layout_height="wrap_content"
android:layout_width="265sp"
android:text="#string/ecsegundo"
android:textColor="#color/Negro"
/>
<Button
android:id="#+id/fracciones"
android:layout_height="wrap_content"
android:layout_width="265sp"
android:text="#string/fracciones"
android:layout_below="#id/ecsegundogrado"
android:textColor="#color/Negro"
/>
<Button
android:id="#+id/maximocomunBoton"
android:layout_height="wrap_content"
android:layout_width="265sp"
android:text="#string/maximocomun"
android:layout_below="#id/fracciones"
android:layout_marginBottom="80sp"
android:textColor="#color/Negro"
/>
</RelativeLayout>
You need to call setContentView before findViewById:
setContentView(R.layout.yourlayoutxmlname);
final Button BtnEcSegundoGrado = (Button)findViewById(R.id.ecsegundogrado);
final Button BtnFracciones = (Button)findViewById(R.id.fracciones);
final Button BtnMCD = (Button)findViewById(R.id.maximocomunBoton);
You need to call setContentView(R.layout.yourxmlLayout); to have the layout being referenced on your activity class.
Try to pop a toast from the click listener and see if it works. If it does - then the problem is in the activity that you want to launch.
You need to add the setContentView(R.layout.yourlayoutxmlname);.
Try the following code:
package com.alexgascon.formuladora;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Matematicas extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.yourlayoutxmlname);
final Button BtnEcSegundoGrado = (Button)findViewById(R.id.ecsegundogrado);
final Button BtnFracciones = (Button)findViewById(R.id.fracciones);
final Button BtnMCD = (Button)findViewById(R.id.maximocomunBoton);
BtnMCD.setOnClickListener( new OnClickListener(){
#Override
public void onClick(View arg0) {
Intent MCDintent = new Intent(Matematicas.this,Maximocomun.class);
startActivity(MCDintent);
}
});
}
}

Android - How to set color of a TextView and background together with SharedPreferences

in my app I have a menu button called "Settings" in which I can choose what colours set up to the background of some layout. Unfortunately I combine two layouts together to show what I want to show, and the problem is that I can only set background colour (that is in a layout) but not the the colour of TextView (that is in the other layout).
Layout main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/main_layout">
<EditText
android:id="#+id/editText1"
android:layout_height="65dip"
android:layout_marginTop="2dip"
android:hint="Scrivi"
android:layout_width="fill_parent" />
<ListView android:id="#+id/list"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fastScrollEnabled="true">
</ListView>
</LinearLayout>
Layout listitem_row.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_layout">
<TextView
android:id="#+id/textView1"
android:text="TextView"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="fill_parent">
</TextView>
<TextView
android:text="TextView"
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
MainActivity:
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Color;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class SearchCocktail extends Activity{
EditText ed;
ListView lview;
String[] first = { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"};
String[] second = { "Uno", "Due", "Tre", "Quattro", "Cinque", "Sei", "Sette", "Otto", "Nove", "Dieci"};
int textlength = 0;
ArrayList<String> first_sort = new ArrayList<String>();
ArrayList<String> second_sort = new ArrayList<String>();
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ed = (EditText) findViewById(R.id.editText1);
lview = (ListView) findViewById(R.id.list);
lview.setAdapter(new MyCustomAdapter(first, second));
...........
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater inflater = getLayoutInflater();
View row;
row = inflater.inflate(R.layout.listitem_row, parent, false);
TextView textview = (TextView) row.findViewById(R.id.textView1);
TextView textview1 = (TextView) row.findViewById(R.id.textView2);
textview.setText(data_first[position]);
textview1.setText(data_second[position]);
return (row);
}
}
#Override
protected void onResume(){
super.onResume();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
Editor editor = prefs.edit();
String colorePref = prefs.getString(PreferencesFromXml.COLORE_PREF, PreferencesFromXml.COLORE_DEFAULT);
int coloreDiSfondo = Color.parseColor(colorePref);
findViewById(R.id.list).setBackgroundColor(coloreDiSfondo);
editor.commit();
}
}
PreferencesFromXml activity:
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
public class PreferencesFromXml extends PreferenceActivity{
public static final String COLORE_DEFAULT = "#000000";
public static final String COLORE_PREF = "colore";
public static final String TITOLO_PREF = "titolo";
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
Editor editor = prefs.edit();
Preference titoloPrefs = findPreference(TITOLO_PREF);
titoloPrefs.setSummary(prefs.getString(TITOLO_PREF, getString(R.string.titolo_custom)));
titoloPrefs.setOnPreferenceChangeListener(new OnPreferenceChangeListener()
{
public boolean onPreferenceChange(Preference prefs, Object value)
{
prefs.setSummary((CharSequence) value);
return true;
}
});editor.commit();
}
}
With my code I can change background colour of layout main.xml but I want change also the TextView colour of listitem_row.xml. I'd like to change the colours together (example: black colour for background and white colour for the text or white colour for the background and black colour for the text, etc.). How can I proceed? Thanks to everyone who can answer.
I don't think I understood PreferenceActivity, PreferenceManager, or your question when I first answered. Your problem is with styling your list, not with storing your preferences, right?
I think setting a theme on the activity might be a solution. This post talks about how to update text colors when the theme is changed. Styles and Themes is probably the place to start reading about themes.

Redraw canvas in Android

I am making an Android 2.2 application using Eclipse. My application should draw
images by clicking on buttons.
I have two buttons at the bottom of the screen, and I need to draw the shape in the same screen that has the buttons. I used FrameLayout in which the shapes are drawn.
My problem is, the two shapes are overwriting, so I need to redraw the canvas.
My Code
package draw.tab;
import android.app.Activity;
//import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
public class DrawActivity extends Activity implements OnClickListener
{
DrawView drawview;
CircleView circleView;
FrameLayout Frame;
Button square,circle;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Frame=(FrameLayout)findViewById(R.id.MyFrame);
drawview=new DrawView(this);
circleView=new CircleView(this);
square=(Button)findViewById(R.id.buttonTest);
square.setOnClickListener(this);
circle=(Button)findViewById(R.id.circleButton);
circle.setOnClickListener(this);
}
public void onClick(View v)
{
switch (v.getId()) {
case R.id.circleButton:
Frame.addView(circleView);
/*circleView.setBackgroundColor(Color.rgb(40,100,20));
circleView.findViewById(R.id.CircleViewId);
setContentView(circleView);*/
break;
case R.id.buttonTest:
Frame.addView(drawview);
/*drawview.setBackgroundColor(Color.WHITE);
drawview.findViewById(R.id.DrawViewId);
drawview.layout(400,0,200,450);
setContentView(drawview);*/
break;
}
}
}
DrawView.java
package draw.tab;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;
public class DrawView extends View
{
Paint paint=new Paint();
Path pat=new Path();
public DrawView(Context context)
{
super(context);
paint.setColor(Color.RED);
paint.setStyle(Style.STROKE);
//context.clearRect(70,140,400,450);
//pat.addRect(50,40,250,400,Path.Direction.CW);
}
public DrawView(Context con,AttributeSet atts)
{
super(con,atts);
}
#Override
public void onDraw(Canvas canvas)
{
//canvas.drawPath(pat,paint);
canvas.drawLine(20,40,450,40,paint);//horizontal top
canvas.drawRect(70,140,400,450,paint);
canvas.drawLine(20,40,20,600,paint);//vertical left
canvas.drawLine(20,600,450,600,paint);//horizontal bottom
canvas.drawLine(450,40,450,600,paint);//vertical right
//this.invalidate();
}
}
CircleView.java
package draw.tab;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;
public class CircleView extends View
{
Paint p=new Paint();
Path path=new Path();
public CircleView(Context context)
{
super(context);
p.setColor(Color.BLUE);
p.setStyle(Style.STROKE);
//path.addCircle(250,250,50,Path.Direction.CW);
}
public CircleView(Context con,AttributeSet atts)
{
super(con,atts);
}
public void onDraw(Canvas c)
{
//c.drawPath(path,p);
//c.save();
c.drawLine(20,40,450,40, p);//horizontal top
c.drawCircle(250,350,100,p);
c.drawLine(20,40,20,600,p);//vertical left
c.drawLine(20,600,450,600,p);//horizontal bottom
c.drawLine(450,40,450,600,p);//vertical right
//c.restore();
this.invalidate();
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:visibility="visible"
android:id="#+id/MyFrame"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<draw.tab.DrawView
android:id="#+id/DrawViewId"
android:layout_width="320dp"
android:layout_height="600dp">
</draw.tab.DrawView>
<draw.tab.CircleView
android:id="#+id/CircleViewId"
android:layout_width="320dp"
android:layout_height="600dp">
</draw.tab.CircleView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="bottom">
<Button
android:layout_height="wrap_content"
android:text="Circle"
android:id="#+id/circleButton"
android:layout_width="160dp">
</Button>
<Button
android:layout_height="wrap_content"
android:text="Square"
android:id="#+id/buttonTest"
android:layout_width="160dp">
</Button>
</LinearLayout>
</FrameLayout>
The above is all my code. The shapes are overwriting, so I want to remove and redraw the canvas or redraw without overwriting.
Try calling invalidate() on your view.
Call canvas.save() then do drawing then call canvas.restore(). Also depends on the bitmaps you are drawing. The bitmaps should have a transparent background.
Edit
Call canvas.drawColor(Color.White); //Or whichever bg color before drawing the bitmap.
Edit
In drawview try this
canvas.drawRect(getLeft(), getTop(), getright() , getBottom() ,paint);
Similarly in CircleView
canvas.drawCircle(getLeft()+getwidth()/2, getTop()+getheight()/2, 100, paint);
One last try. Set children gravity..
<draw.tab.DrawView
android:id="#+id/DrawViewId"
android:layout_width="320dp"
android:layout_height="600dp"
android:layout_gravity="left">
</draw.tab.DrawView>
<draw.tab.CircleView
android:id="#+id/CircleViewId"
android:layout_width="320dp"
android:layout_height="600dp"
android:layout_gravity="right">
</draw.tab.CircleView>

Categories

Resources