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)


328

Screen size density independent pixel resolution | screen-size-density-independent-pixel-resolution


Terms Screen size, density, density independent pixel, resolution as a picture - pictogram.
mobile-phone-screen-resolution-terms

Test your knowledge
Q: How to find out the phone screen size?
A: (By length of display diagonale in inch -  Not to measure a diagonal of device!!!)

Q: What resolution has 720 x 1280 display?
A: (921600 pixels)

Q: What does it mean "240 dpi" screen density?
A: (Display have density 240 x 240  dots - "Tri-color LED etc." - per every physical (real) square inch. If you have icon 240x240 pixels, this will just occupy an area of one square inch on the display.)

Q: Phone have screen density 240 dpi. Image for 160 dpi screen density have size 128x 128 pixels. What will be the size of the image for 240 dpi screen density?
A: (Calculate the virtual pixels size.   128 * (240/160)  =  192.  You have to resize image to new size 192 x 192 physical pixels and put into folder drawable-hdpi (high) ~240dpi  for phone with screen density 240 dpi. ) or use density independend pixels 128dp x 128dp.

 

 
285

Unable to resolve target android | unable-to-resolve-target-android


Unable to resolve target android-7
Try this solution:
Select project from tree (project explorer)
- right click on project
- properties
- select Android from tree
- change Project Build Target to higher (or change project build target)
- selct from menu: Project-Clean ( select your project - OK)
332

Lenovo A6000 smartphone pictures from camera 8mpx review | lenovo-a6000-smartphone-pictures-from-camera-8mpx


Pictures taken by front camera Lenovo A6000 smartpohone - review.
Do not take pictures against the sun.
Stay in the shade. Keep lens clean.

Night without flash

Lenovo A6000 pictures quality
Lenovo A6000 pictures quality
Lenovo A6000 pictures quality
Lenovo A6000 pictures quality




Misty - smog


Without flash in room - TV screen


lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
55

How update View TextView with timer Android runnable example | how-update-view-textview-with-timer-android-runnable-example


Update TextView by runnable. Handler, runnable, timer Android example.


public class TimerActivity extends Activity {
TextView hTextView;
Button hButton, hButtonStop;
private Handler mHandler = new Handler();
private int nCounter = 0;
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        hTextView = (TextView)findViewById(R.id.idTextView);
        hButton = (Button)findViewById(R.id.idButton);
        hButton.setOnClickListener(mButtonStartListener);
        hButtonStop = (Button)findViewById(R.id.idButtonStop);
        hButtonStop.setOnClickListener(mButtonStopListener);
    } // end onCreate

View.OnClickListener mButtonStartListener = new OnClickListener() {
	public void onClick(View v) {
		try {
			mHandler.removeCallbacks(hMyTimeTask);
         //        Parameters
         //        r  The Runnable that will be executed. 
         //        delayMillis  The delay (in milliseconds) until the Runnable will be executed. 
                       mHandler.postDelayed(hMyTimeTask, 1000); // delay 1 second
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
};


private Runnable hMyTimeTask = new Runnable() {
	   public void run() {
		   nCounter++;
	    	   hTextView.setText("Hallo from thread counter: " + nCounter);
	   }
	}; 
/**
 * 
 */
    View.OnClickListener mButtonStopListener = new OnClickListener() {
    	public void onClick(View v) {
    		 mHandler.removeCallbacks(hMyTimeTask);
    		
    	}
    };
}





main.xml



<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
	android:id="@+id/idTextView"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
<Button android:text="Button" 
android:id="@+id/idButton" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"></Button>
 
 <Button android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:id="@+id/idButtonStop" 
 android:text="Stop"></Button> 
    
    
</LinearLayout>




262

Font Family change on View dynamically Android Example | font-family-change-on-view-android-example


TypeFace, setTypeface, font, font family, array of String, Button create dynamically

@Override
protected void onStart() {
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
  48,
  55
);	
Typeface typeFace = Typeface.MONOSPACE;	
String [] ar = {"A","B","C","D","E","F","G","H","J","K"};
for (int i = 0; i < ar.length; i++) {
Button buttonView = new Button(this);
buttonView.setText(Html.fromHtml("<b>"+ar[i]+"</b>"));
buttonView.setTextColor(Color.BLUE);
buttonView.setTextSize(27.f);
buttonView.setTypeface(typeFace,Typeface.BOLD);
buttonView.setOnClickListener(mThisButtonListener);
if(i%2==0)
	mLayoutButtons.addView(buttonView, p);
else
	mLayoutButtonsNextRow.addView(buttonView, p);
	
_listOfButtons.add(buttonView);
}

	super.onStart();
}

//////// xml file
<TextView
    android:id="@+id/text01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="20dp"
    android:fontFamily="Arial"
 />


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