Adding two buttons which are touching each other in Framelayout - android

I want to add two buttons one below another in a FrameLayout but they should be touching. However, I am not managing to do this. Here is my code:
<FrameLayout
android:id="#+id/lytOptions"
android:layout_below="#id/imgLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/action_via_email"
android:textColor="#android:color/white"
android:textStyle="bold" />
<Button
android:id="#+id/btnSignUp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/action_sign_up"
android:textColor="#android:color/white"
android:textStyle="bold" />
</FrameLayout>

Try this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="49dp"
android:text="Button" />
</RelativeLayout>
to get the output like this

Use vertical LinearLayout instead...
<LinearLayout
android:layout_width="fill_parent"
android:layout_below="#id/imgLine"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="#+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/action_via_email"
android:textColor="#android:color/white"
android:textStyle="bold" />
<Button
android:id="#+id/btnSignUp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/action_sign_up"
android:textColor="#android:color/white"
android:textStyle="bold" />
</LinearLayout>

By using framelayout you are actually placing one image on another, instead use linearlayout with buttons width and height as wrap content,and avoid using layout weights of the buttons.
Let me know if this solves your problem

As others have pointed out, the key answer is to use a LinearLayout to position the buttons next to each other. However, to a "touching" effect, you will need to do one or more of the following:
Change the padding on each Button.
Change the margin on each Button.
Change the button background image so that it goes right to the edge of the View area.
My preference would be to set the margins and paddings to zero and to set the image to be the effect you want:
<LinearLayout
android:layout_width="fill_parent"
android:layout_below="#id/imgLine"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- options 1 and 2 -->
<Button
android:id="#+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/action_via_email"
android:textColor="#android:color/white"
android:padding="0dp" <!-- Set there to be no space between the content and the surrounding views -->
android:padding="0dp" <!-- Set to be no space int the content area but between the content and the edge of the content area -->
android:textStyle="bold" />
<!-- option 3 -->
<Button
android:id="#+id/btnSignUp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/action_sign_up"
android:textColor="#android:color/white"
android:background="#drawable/my_background"
android:textStyle="bold" />
</LinearLayout>
You will need to define my_background as an imagine the drawable directory or res. You may the section on 9 patch images from http://developer.android.com/guide/topics/graphics/2d-graphics.html helpful.

Use a TableLayout instead:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" android:background="#drawable/button_style"/>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" android:background="#drawable/button_style"/>
</TableRow>
</TableLayout>
Assign a drawable button_style to the buttons:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#38393B"/>
<stroke android:width="0.5dp" android:color="#8aaa"/>
<size android:width="120dp" android:height="80dp" />

Related

Three buttons evenly divided linear layout

So, I am trying to use a linear layout to hold three different buttons, each should take up 33% of the width on one line. This linear layout will be below all the other content in my relative layout, which holds all the other widgets on this activity. Unfortunately, when I add the third button into the layout, the other two have a white bar along the bottom of them and the third button (in this case the home button) is positioned higher than the others.
Can someone explain this behavior and how to rectify it? Thanks.
This is the XML file for the linear layout, I've removed all the text for the other widgets. If that would be helpful, I can post it as well.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<Button
android:layout_width="0dp"
android:layout_weight=".33"
android:layout_height="wrap_content"
android:text="#string/adfazsdfasdfadfsagjlfkdlgjklfsadgfjgps"
android:onClick="resetDates"
android:background="#drawable/sumbitstyleing"
android:id="#+id/resetDatesButton" />
<Button
android:layout_width="0dp"
android:layout_weight=".33"
android:layout_height="wrap_content"
android:text="#string/home"
android:onClick="home"
android:id="#+id/homeButtonSearch"
android:background="#drawable/generalbutton" />
<Button
android:layout_weight=".33"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/submitchanges"
android:onClick="submitChanges"
android:background="#drawable/sumbitstyleing"
android:id="#+id/submitchanges" />
</LinearLayout>
The first picture is WITHOUT the third button, the second picture is WITH the third button.
Try this, I have removed Properties you should use with RelativeLayout and unnecessary with LinearLayout, and buttons aligned horizontally,
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
and assigned Weightsum to LinearLayout along with button height to match parents
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="1">
<Button
android:id="#+id/resetDatesButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:onClick="resetDates"
android:text="Rese check dates" />
<Button
android:id="#+id/homeButtonSearch"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:onClick="home"
android:text="home" />
<Button
android:id="#+id/submitchanges"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:onClick="submitChanges"
android:text="submit changes" />
</LinearLayout>
</RelativeLayout>
Result
Here you can go this way :
<?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="#color/white"
>
<LinearLayout
android:layout_width="300dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerHorizontal="true"/>
<!--Buttons -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="3"
>
<android.support.v7.widget.AppCompatButton
android:id="#+id/motor_team_send_sms_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/send_sms"
/>
<android.support.v7.widget.AppCompatButton
android:id="#+id/motor_team_sleep_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/sleep"
/>
<android.support.v7.widget.AppCompatButton
android:id="#+id/motor_team_rise_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/rise"
/>
</LinearLayout>
Output is:
This might help you.
Try this, in your LinearLayout add android:gravity="center"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center">
...
</LinearLayout>

Android: Adding a divider into a list item with dynamic height

I'm currently trying to create a list item similar to the one in the official design guidelines. Still missing is the vertical divider next to the button/image on the right side of each item. Most people seem to use a separate View with a fixed width for that, but the height doesn't scale in my case. It's only shown when I set a fixed height for the divider itself or the parent RelativeLayout. Is it possible to let it scale automatically?
My layout XML for the list item looks like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/sensors_list_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="10dp" />
<TextView
android:id="#+id/sensors_list_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_toRightOf="#id/sensors_list_img"
android:paddingTop="5dp" />
<TextView
android:id="#+id/sensors_list_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:layout_below="#id/sensors_list_name"
android:layout_toRightOf="#id/sensors_list_img"
android:paddingBottom="5dp" />
<ImageView
android:id="#+id/sensors_list_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:padding="10dp"
android:src="#drawable/ic_angle_right" />
<View
android:id="#+id/sensors_list_divider"
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_toLeftOf="#id/sensors_list_details"
android:background="#ff0000" />
</RelativeLayout>
Try to assign an height related to the image like:
android:alignTop="#id/myimage"
android:alignBottom="#id/myimage"
otherwise you can create a xml drawable and use it with an ImageView :
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:width="1dp" android:color="#000000"/>
</shape>
Update
Remember android:shape="line" doesn't work without stroke
Let's go with a LinearLayout as a parent:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/sensors_list_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingTop="5dp" />
<TextView
android:id="#+id/sensors_list_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:paddingBottom="5dp" />
</LinearLayout>
<View
android:id="#+id/sensors_list_divider"
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#ff0000" />
<ImageView
android:id="#+id/sensors_list_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:src="#drawable/ic_angle_right" />
</LinearLayout>
Check this
listView.setDividerHeight(1);

Long text in Android TextView pushes out other Objects

I have created a ListView which shows different media files with the possibility to play them.
Each row consists of a RelativeLayout with two widgets. (The SeekBar and the Rest)
The upper part of this RelativeLayout is a RelativeLayout too.
It consists of three parts:
A play button (inside a LinearLayout for padding)
A TextView for the file name
A LinearLayout box containing some labels
They are put together using the android:layout_toRightOf property.
This works quite well, unless the file name is extremely long.
A long file name causes the right LinearLayout 'Box' to be pushed outside the screen.
In addition the whole (inner) RelativeLayout gets stretched vertically without reason.
I have already tried to setandroid:ellipsize="end" and android:singleLine="true". But that didn't fix it.
Heres the full code:
<?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"
android:orientation="horizontal"
android:padding="8dp" >
<!-- Top Box -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/fragment_play_row_topbox" >
<!-- Play button -->
<LinearLayout android:id="#+id/fragment_play_row_iconBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="4dip" >
<ImageButton
android:id="#+id/fragment_play_row_icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="#android:drawable/ic_media_play" />
</LinearLayout>
<!-- Big Text -->
<TextView
android:id="#+id/fragment_play_row_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/fragment_play_row_iconBox"
android:text="\??"
android:textSize="24dp"
android:ellipsize="end"
android:singleLine="true" />
<!-- Size & Duration & Button-->
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/fragment_play_row_text"
android:layout_alignParentRight="true"
android:gravity="right" >
<TextView
android:id="#+id/fragment_play_row_size"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text=" ?? MB" />
<TextView
android:id="#+id/fragment_play_row_duration"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text=" ??:??" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="#android:drawable/arrow_down_float" />
</LinearLayout>
</RelativeLayout>
<!-- Seek Bar -->
<SeekBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/fragment_play_row_topbox" />
</RelativeLayout>
I hope someone can help me fix this.
Thanks in advance,
Uriel
You have to reference as the info layout as the root of your items, referencing it to the parent and the text referencing to the info layout, by this way you will not have this problem, I've modified a little bit your layout just adding an id to the info layout (linearInfo), remmember when you set an id is "#+id/my_item" but when you are referencing to it is "#id/my_item", here is your layout modified, hope it helps you:
<?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"
android:orientation="horizontal"
android:padding="8dp" >
<!-- Top Box -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/fragment_play_row_topbox" >
<!-- Play button -->
<LinearLayout
android:id="#+id/fragment_play_row_iconBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/linearInfo"
android:layout_alignTop="#+id/linearInfo"
android:padding="4dip" >
<ImageButton
android:id="#+id/fragment_play_row_icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center_vertical"
android:src="#android:drawable/ic_media_play" />
</LinearLayout>
<!-- Big Text -->
<TextView
android:id="#+id/fragment_play_row_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/linearInfo"
android:layout_alignTop="#+id/linearInfo"
android:layout_centerVertical="false"
android:layout_toLeftOf="#+id/linearInfo"
android:layout_toRightOf="#+id/fragment_play_row_iconBox"
android:ellipsize="end"
android:gravity="center_vertical"
android:singleLine="true"
android:text="\?? Ultra Hyper Mega Giant Text"
android:textSize="24dp" />
<!-- Size & Duration & Button-->
<LinearLayout
android:id="#+id/linearInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:id="#+id/fragment_play_row_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" ?? MB" />
<TextView
android:id="#+id/fragment_play_row_duration"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text=" ??:??" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="#android:drawable/arrow_down_float" />
</LinearLayout>
</RelativeLayout>
<!-- Seek Bar -->
<SeekBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/fragment_play_row_topbox" />
</RelativeLayout>

How to create a Relative layout with multiple buttons compatible for all screen sizes?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/lyt_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/plain_bg"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/lyt_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/header" />
</LinearLayout>
<LinearLayout
android:id="#+id/lyt_body"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/lyt_Buttons"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imgfrontlogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imgcenterlogo"
android:layout_alignParentTop="true"
android:layout_marginTop="61dp"
android:background="#drawable/front_logo"
/>
<ImageView
android:id="#+id/imgcenterlogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/btnPersonaltrainer"
android:layout_centerHorizontal="true"
android:layout_marginBottom="29dp"
android:background="#drawable/center_logo" />
<Button
android:id="#+id/btnMyProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="21dp"
android:layout_marginLeft="32dp"
android:background="#drawable/myprofile" />
<Button
android:id="#+id/btnTaracker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imgcenterlogo"
android:layout_alignParentRight="true"
android:layout_marginBottom="49dp"
android:background="#drawable/track" />
<Button
android:id="#+id/btnPersonaltrainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/btnMyProfile"
android:layout_alignLeft="#+id/btnAllExercises"
android:background="#drawable/personaltrainer" />
<Button
android:id="#+id/btnRandomworkouts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/btnPersonaltrainer"
android:layout_alignParentLeft="true"
android:background="#drawable/randomworkout" />
<Button
android:id="#+id/btnAllworkouts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/btnAllExercises"
android:layout_alignBottom="#+id/btnAllExercises"
android:layout_alignLeft="#+id/btnMyProfile"
android:background="#drawable/allworkouts" />
<Button
android:id="#+id/btnAllExercises"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/btnTaracker"
android:layout_alignParentRight="true"
android:layout_marginRight="40dp"
android:background="#drawable/allexercises" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>`
I need to create layout compatible for all screen sizes,created separte layout for xlarge sizes(800x1280,720x1280 etc). Here I cant upload image due to reputation,need to place one main button on center of the layout ,place 3 buttons on curvely on left and right side of middle button.please can anyone help me to create the layout compatible for all screen sizes without using dp or fixed points.
you can use android:layout_weight attribute. It will allow you to use percentages to define your buttons.
For EX:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1.0" >
<Button
android:text="left"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".50" />
<Button
android:text="right"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".50" />
</LinearLayout>
Now you have given percentages values to buttons so they will be displayed on any size of screen to their percent value of the whole screen.
This can be done in LinearLayout for RelativeLayout check second answer on this link
As mentioned in the question you want the buttons to be placed curvely at left and right of a center button, you can have a look at the link to get some idea to how to accomplish this: https://github.com/daCapricorn/ArcMenu
This is an open source project which I referred to create a Path like menu.

Android text will not align to center

I have a TextView and 3 Buttons centered in a RelativeLayout, and the text in all three of them is left-justified with the parent center as the leftmost line.
I've tried changing the gravity of the TextView, Buttons, and layout but nothing is working and I'm baffled because I've never seen Android align text like this before.
I want the Button text to be centered within each Button and the top text to be center-justified.
An image of what it looks like is here: http://i.stack.imgur.com/9lHEd.png
Here's my 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" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="20dp"
android:gravity="center_horizontal"
android:text="#string/greeting"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/startQuizButton"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:onClick="#string/startQuiz"
android:text="#string/start_quiz" />
<Button
android:id="#+id/lessonsButton"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_below="#+id/startQuizButton"
android:layout_centerHorizontal="true"
android:onClick="#string/startLesson"
android:text="#string/lessonsString" />
<Button
android:id="#+id/viewAllButton"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_below="#+id/lessonsButton"
android:layout_centerHorizontal="true"
android:onClick="#string/showAll"
android:text="#string/view_all" />
I included a RelativeLayout because you have it as your parent layout. However, i am not sure that it is needed. See if the following code is what you are looking for.
<?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"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Greetings" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Start Quiz" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Lessons" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="View all questions" />
</LinearLayout>
</RelativeLayout>
add in button tab android:gravity="center"...see if it works..
u need to set layout width and height to fill_parent and everything will work fine
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="your text" />
if you want to centre some text, then you could also do it this way:
<TextView
android:text="Quantity"
android:textSize="34sp"
android:textColor="#ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:layout_centerHorizontal="true"
android:paddingTop="10dp"/>
here i have changed made it horozontal by using android:layout_centerHorizontal="true"which takes a boolean value of true or false, by making it true, it will automatically be centred on all devices
hope that helps

Categories

Resources