Switch case in Android app - android

Here is the code that supposed to open a dialog box when i press the About button in my min activity page. But nothing really happens. : /
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View continueButton = findViewById(R.id.continue_button);
continueButton.setOnClickListener(this);
View newgameButton = findViewById(R.id.new_button);
continueButton.setOnClickListener(this);
View aboutButton = findViewById(R.id.about_button);
continueButton.setOnClickListener(this);
View exitButton = findViewById(R.id.exit_button);
continueButton.setOnClickListener(this);
public void onClick(View v) {
switch (v.getId()) {
case R.id.continue_button:
break;
case R.id.about_button:
Intent i = new Intent(this, About.class);
startActivity(i);
break;
case R.id.new_button:
openNewGameDialog();
break;
case R.id.exit_button:
finish();
break;
}
}
Main Activity XML
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/background"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:padding="30dip"
android:orientation="horizontal" >
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="center" >
<TextView
android:text="#string/main_title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="25dip"
android:textSize="24.5sp" />
<Button
android:id="#+id/continue_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/continue_label" />
<Button
android:id="#+id/new_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/new_game_label" />
<Button
android:id="#+id/about_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/about_label" />
<Button
android:id="#+id/exit_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/exit_label" />
</LinearLayout>
</LinearLayout>
Example of a button: About
About Activity
public class About extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.about, menu);
return true;
}
}
About XML
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip" >
<TextView
android:id="#+id/about_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/about_text" />
</ScrollView>

Here's your problem:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View continueButton = findViewById(R.id.continue_button);
continueButton.setOnClickListener(this);
View newgameButton = findViewById(R.id.new_button);
**newgameButton**.setOnClickListener(this);
View aboutButton = findViewById(R.id.about_button);
**aboutButton**.setOnClickListener(this);
View exitButton = findViewById(R.id.exit_button);
**exitButton**.setOnClickListener(this);
}
Only your 'continueButton' has an onClickListener registered...
Also:
It is good practice to also have a default case in a switch statement which gets executed if none of the cases hold. Add a default case with a log message or something and see if it gets executed.

First, make sure your activity implements View.OnClickListener interface.
Secondly, try to add #Override before the public void onClick(View view) { } method declaration. If this does not help, try to add a log statement at top of the onClick method, for example logging the ID of the view, and compare it to the ones you're trying to match it against.

As far as i can say, you need to call button.setOnClickListener(this); in your activity onCreate method

Related

Multiple Activities in Android Studio

I'm new to Android. I'm trying to test 2 Activities in my project where when I click on a button in my first Activity, it should take me to the second Activity. Here I have given a click event to my button but when I run the project, I'm unable to see anything, its just a blank screen. What am I missing ?
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void onAddCLick(View view) {
Intent TaskIntent = new Intent(this,SecondScreen.class);
startActivity(TaskIntent);
}
}
This is the second activity :-
public class SecondScreen extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_layout);
Intent task = getIntent();
}
public void cancl_btn(View view) {
Intent goBack = getIntent();
finish();
}
}
This is activity_main.xml :-
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="left"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ListView
android:layout_width="wrap_content"
android:layout_height="516dp"
android:id="#+id/theListView">
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/add_task"
android:onClick="onAddCLick"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/setloc"
android:onClick="onMapbtnClck"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/settings"
android:onClick="onSetngClck"/>
</LinearLayout>
This is second_layout.xml :-
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="left">
<EditText
android:layout_width="364dp"
android:layout_height="wrap_content"
android:id="#+id/task_name_edit_txt"
android:text="Enter your Details here" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Set Location"
android:id="#+id/textView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Set_loc_btn"
android:onClick="set_usr_loc"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Add_task_btn"
android:onClick="add_usr_tsk_btn"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cancel_btn"
android:onClick="cancl_btn"/>
</LinearLayout>
</LinearLayout>
Use this code:
In first activity:
public void onAddCLick(View view) {
Intent TaskIntent = new
Intent(MainActivity.this,SecondScreen.class);
startActivity(TaskIntent);
}
In second Activity:
public void cancl_btn(View view) {
Intent goBack =new
Intent(SecondScreen.this,MainActivity.class);
startActivity(goBack);
}
by assuming that you have posted the complete XML file of the second layout,, I tried running it on my android studio and as you can see in the xml file itself you are missing lot of information in it,,,
you need to define the schema as you have done in the first xml and
the < EditText > tag cannot be outside a container, you need to place it inside the container, that is, inside any kind of layout (linear, relative etc)..
if the issue is with the xml file then modifying it as per above two points will solve your problem,, hope this helps

Android Button click does not work with SliderLayout in RelativeLayout

In my XML layout, I use SliderLayout in RelativeLayout where height and width are match_parent. I have a skip button to finish activity. I think SliderLayout overrides the skip button so I can not use the click event of button. It does not work. How can I avoid of this problem?
activity_tutorial.xml
<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"
android:background="#color/White" >
<Button
android:id="#+id/skipButton"
style="#style/button_type"
android:layout_width="#dimen/dp_150"
android:layout_height="#dimen/dp_40"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/dp_20"
android:text="#string/skip" />
<com.daimajia.slider.library.SliderLayout
android:id="#+id/imageSlider"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true" />
<com.daimajia.slider.library.Indicators.PagerIndicator
android:id="#+id/custom_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
TutorialActivity.java
public class TutorialActivity extends Activity implements
OnSliderClickListener, OnClickListener {
private static final String FONTH_PATH_BUTTON = "fonts/Brandon_bld.otf";
private Typeface buttonFont;
private Button skipButton;
private SliderLayout mDemoSlider;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tutorial);
buttonFont = Typeface.createFromAsset(getAssets(), FONTH_PATH_BUTTON);
skipButton = (Button) findViewById(R.id.skipButton);
skipButton.setTypeface(buttonFont);
skipButton.setOnClickListener(this);
mDemoSlider = (SliderLayout) findViewById(R.id.imageSlider);
HashMap<String, Integer> file_maps = new HashMap<String, Integer>();
file_maps.put("Challenge", R.drawable.tutorial_challenge);
file_maps.put("Select", R.drawable.tutorial_select);
file_maps.put("Image", R.drawable.tutorial_image);
file_maps.put("Friend", R.drawable.tutorial_friend);
for (String name : file_maps.keySet()) {
TextSliderView textSliderView = new TextSliderView(this);
// initialize a SliderLayout
textSliderView.description(name).image(file_maps.get(name))
.setScaleType(BaseSliderView.ScaleType.Fit)
.setOnSliderClickListener(this);
// add your extra information
textSliderView.getBundle().putString("extra", name);
mDemoSlider.addSlider(textSliderView);
}
mDemoSlider.setPresetTransformer(SliderLayout.Transformer.Accordion);
mDemoSlider
.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
mDemoSlider.setCustomAnimation(new DescriptionAnimation());
mDemoSlider.setDuration(4000);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.tutorial, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onSliderClick(BaseSliderView slider) {
// TODO Auto-generated method stub
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.skipButton:
finish();
break;
default:
break;
}
}
}
Simply open XML and add the Button in your SliderLayout body. It can be set by dragging the button on top of the SliderLayout.
Your code:
<Button
android:id="#+id/skipButton"
style="#style/button_type"
android:layout_width="#dimen/dp_150"
android:layout_height="#dimen/dp_40"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/dp_20"
android:text="#string/skip" />
<com.daimajia.slider.library.SliderLayout
android:id="#+id/imageSlider"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true" />
Change it to:
<com.daimajia.slider.library.SliderLayout
android:id="#+id/imageSlider"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true" >
<Button
android:id="#+id/skipButton"
style="#style/button_type"
android:layout_width="#dimen/dp_150"
android:layout_height="#dimen/dp_40"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/dp_10"
android:text="#string/skip" />
</com.daimajia.slider.library.SliderLayout>
That should do it. Hope it helps. :)
<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"
android:background="#color/White" >
<com.daimajia.slider.library.SliderLayout
android:id="#+id/imageSlider"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true" >
<Button
android:id="#+id/skipButton"
style="#style/button_type"
android:layout_width="#dimen/dp_150"
android:layout_height="#dimen/dp_40"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/dp_10"
android:text="#string/skip" />
</com.daimajia.slider.library.SliderLayout>
<com.daimajia.slider.library.Indicators.PagerIndicator
android:id="#+id/custom_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
Just move button inside of SliderLayout solves my problem.

React to events on custom Dialog - android

this is acceuilActivity :
public class AcceuilActivity extends FragmentActivity {
private GoogleMap mMap;
Button handle,b1,b2,b3,b4;
RadioGroup choixSignalGroup;
RadioButton ChoixSignalButton;
Button signaler,annuler;
SlidingDrawer slidingDrawer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_acceuil);
SupportMapFragment mapFrag = (SupportMapFragment) this.getSupportFragmentManager().findFragmentById(R.id.map);
mMap = mapFrag.getMap();
handle = (Button) this.findViewById(R.id.handle);
slidingDrawer = (SlidingDrawer) findViewById(R.id.slidingDrawer1);
b1 = (Button) findViewById(R.id.b1);
b1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Dialog d = new Dialog(AcceuilActivity.this);
d.setContentView(R.layout.dialog_signal);
d.setTitle("Signalement");
choixSignalGroup = (RadioGroup) findViewById(R.id.radioGroup1);
signaler = (Button) findViewById(R.id);
d.show();
}
});
b2 = (Button) this.findViewById(R.id.b2);
b3 = (Button) this.findViewById(R.id.b3);
b4 = (Button) this.findViewById(R.id.b4);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.acceuil, menu);
return super.onCreateOptionsMenu(menu);
}
}
this is dialog_signal :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical" >
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Encombrement" />
<RadioButton
android:id="#+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Accident" />
<RadioButton
android:id="#+id/radio3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Danger" />
<RadioButton
android:id="#+id/radio4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Barrage" />
<RadioButton
android:id="#+id/radio5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Traveaux" />
</RadioGroup>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/signaler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Signaler" />
<Button
android:id="#+id/annuler"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:text="Annuler" />
</LinearLayout>
</LinearLayout>
when i called radio group from the custom dialog layout (dialog_signal) it worked but when i tried to call a button (signaler) from the same layout it didn't work ! please help
Create dialog like this :
public void createDialog() {
Dialog dialog = new Dialog(YourActivity.this);
dialog.setContentView(R.layout.custom_dialog_layout);
dialog.setTitle("Select");
dialog.setCancelable(true);
final Spinner spn = (Spinner) dialog.findViewById(R.id.spinner1);
dialog.show();
}
Assume that there is a spinner in the custom xml layout. Use dialog.findViewById(), to find the id from the layout. You can create listener methods below that code.
As far as putting it in which activity is concerned, you have to determine that. Wherever you want to launch the dialog from, simply call the method. But, do remember to create this method in the activity, from which you intend to launch the dialog.
Use RadioGroup the same way as spinner, and you'll be ready to roll.

Placing Two Image Buttons on Top of Each Other

I need to place two ImageButtons on top of each other something like the following image.
While placing them has been no issue, I am unable to click the blue button. The red button when clicked works perfectly well.
The XML layout code is as follows:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<ImageButton
android:id="#+id/bluebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:onClick="onButtonClicked"
android:scaleType="fitCenter"
android:src="#drawable/bluebutton" />
<ImageButton
android:id="#+id/redbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:onClick="onButtonClicked"
android:scaleType="fitCenter"
android:src="#drawable/redbutton" />
</FrameLayout>
How do i ensure that both buttons can be clicked ?
You can simply use a RelativeLayout to do that. See this I made just now:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageButton btn = (ImageButton)findViewById(R.id.bluebutton);
ImageButton btn2 = (ImageButton)findViewById(R.id.redbutton);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TextView t = (TextView)findViewById(R.id.txt);
t.setText("Hello!");
}
});
btn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TextView t = (TextView)findViewById(R.id.txt);
t.setText("Hi, how are you?");
}
});
}
it's just an example
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ImageButton
android:background="#ff040ab2"
android:id="#+id/bluebutton"
android:layout_width="150dp"
android:layout_height="250dp"
android:onClick="onButtonClicked"
android:scaleType="fitCenter"/>
<ImageButton
android:rotation="90"
android:background="#be2222"
android:id="#+id/redbutton"
android:layout_width="150dp"
android:layout_height="250dp"
android:onClick="onButtonClicked"
android:scaleType="fitCenter"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txt"
android:textColor="#ffffff"/>
</RelativeLayout>
Changed the code.
public class MainActivity extends Activity {
ImageButton red,blue;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
red = (ImageButton)findViewById(R.id.redbutton);
blue = (ImageButton)findViewById(R.id.bluebutton);
}
public void onRedButtonClicked(final View view) {
Toast.makeText(getApplicationContext(), "Button red is clicked!", Toast.LENGTH_SHORT).show();
}
public void onBlueButtonClicked(final View view) {
Toast.makeText(getApplicationContext(), "Button blue is clicked!", Toast.LENGTH_SHORT).show();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
And the layout:
<FrameLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageButton
android:id="#+id/redbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:onClick="onRedButtonClicked"
android:scaleType="fitCenter"
android:src="#drawable/redbutton"
android:visibility="visible"/>
<ImageButton
android:id="#+id/bluebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:onClick="onBlueButtonClicked"
android:scaleType="fitCenter"
android:src="#drawable/bluebutton"
android:visibility="visible"/>
</FrameLayout>
Hope this helps..:)

How to setting listener for button inside the Crouton Toast and clear that Crouton Toast using that button?

I have an app, which shows toast below the actionbar. I'm using Crouton library for displaying toast. Here I'm placing custom layout for toast, that layout contains one textview and one button (for close option). So Toast appears with button. If I click that it should close the toast but nothing happens.. Below Code for this example. Any Help Appreciated
MainActivity.java
public class MainActivity extends SherlockActivity implements OnClickListener {
private View customToastView;
private TextView customToastMessageView;
private Button customToastCloseButton;
private Button doneButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
doneButton = (Button) findViewById(R.id.done_button);
customToastView = getLayoutInflater().inflate(R.layout.toast_custom_layout, null);
customToastMessageView = (TextView) customToastView.findViewById(R.id.messages);
customToastCloseButton = (Button) customToastView.findViewById(R.id.close_button);
customToastCloseButton.setOnClickListener(this);
doneButton.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.done_button:
Crouton.cancelAllCroutons();
customToastMessageView.setText("Message");
Crouton.show(this, customToastView);
break;
case R.id.close_button:
Crouton.cancelAllCroutons();
break;
}
}
}
toast_custom_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/messages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="26dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="23dp"
android:text="Button" />
</RelativeLayout>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/done_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="146dp"
android:text="Button" />
</RelativeLayout>

Categories

Resources