Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Center View in RelativeLayout Android


AD MOB

RelativeLayout like parent, child Srollview is centered horizontal.
Second RelativeLayout in SrollView have gravity center, every child will centered horizontally and vertically.


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="//schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:gravity="center_horizontal">

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/scrollView2" >

        <RelativeLayout
            android:layout_width="320dp"
            android:layout_height="wrap_content"
            android:background="#e6f825"
            android:gravity="center">

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="New Button"
                android:id="@+id/button" />
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>

397LW NO topic_id




AD

Další témata ....(Topics)


106

Statistics usability of mobile phones with Android - September 2011 | statistics-usability-of-mobile-phones-with-android-september-2011


(Our software)

 
1Samsung Galaxy S213.8% (1,232)
2Samsung Galaxy S8.5% (762)
3Samsung Galaxy Tab7.4% (659)
4Samsung Galaxy Mini5.4% (483)
5Samsung Galaxy S4.0% (356)
6HTC Desire HD3.8% (341)
7Samsung Galaxy Ace3.8% (339)
8HTC Wildfire3.2% (286)
9Samsung Galaxy Fit3.1% (274)
10SEMC Xperia X102.1% (190)
186

Set Drawable programmatically Android example | set-drawable-programmatically-android-example



// start_dark.png is stored in path	/package_name/res/drawable/start_dark.png
Drawable dw = getApplicationContext().getResources().getDrawable(R.drawable.start_dark);
Button hButtonStart = (Button)findViewById(R.id.buttonStart);
hButtonStart.setCompoundDrawablesWithIntrinsicBounds(dw, null, null, null);

299

R cannot be resolved to a variable | r-cannot-be-resolved-to-a-variable


Check your xml files in Eclipse Graphical Editor and fix problems.

r-cannot-be-resolved-android

Check project setup, right click on project, select properties, Java build path and
select correct Android version etc.
order-and-export-eclipse-android-project

Right click on project, Android Tools, Fix Project Properties

Menu Eclipse select Project ->Clean.
142

Create bitmap and draw text into bitmap Android example | create-bitmap-and-draw-text-into-bitmap-android-example



public class ApokusActivity extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static class SampleView extends View {

		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);

		}
		@Override
		protected void onDraw(Canvas canvas) {
			Paint paint = new Paint();
			
			canvas.drawColor(Color.GREEN);
            
           Bitmap b = Bitmap.createBitmap(200, 200, Bitmap.Config.ALPHA_8);
           Canvas c = new Canvas(b);
           c.drawRect(0, 0, 200, 200, paint);
           
           paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
           paint.setTextSize(40);
           paint.setTextScaleX(1.f);
           paint.setAlpha(0);
           paint.setAntiAlias(true);
           c.drawText("Your text", 30, 40, paint);
           paint.setColor(Color.RED);
           
           canvas.drawBitmap(b, 10,10, paint);
		}

	}
}


draw-text-into-bitmap-android

136

Draw Path drawPath draw the trajectory of shot Android basic example | draw-path-drawpath-android-basic-example


Draw the trajectory of shot.

public class MainActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static class SampleView extends View {

		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);

		}
	       private static void makePath(Path p) {
	            p.moveTo(10, 0);
	            p.cubicTo(100, -50, 200, 150, 300, 0);
	        }
		@Override
		protected void onDraw(Canvas canvas) {

			canvas.drawColor(Color.CYAN);
			Paint p = new Paint();
			// smooths
			p.setAntiAlias(true);
			p.setColor(Color.RED);
			p.setStyle(Paint.Style.STROKE); 
			p.setStrokeWidth(5);
			// opacity
			//p.setAlpha(0x80);
 
			p.setColor(Color.BLACK);
			Path mPath = new Path();
            makePath(mPath);
			canvas.drawPath(mPath, p); //(rectF, 90, 45, true, p);
		}

	}
}


Editace: 2016-03-14 17:39:25
Počet článků v kategorii: 397
Url:center-view-in-relativelayout-android

AD
11 Share
Share
Tweet