I have tried everything but not succeed yet.
What Happening. When title text is small it should come in center of parent which works perfectly, but when text size is big its overlapped to its left sided component
What i want : it shouldn't not overlap but comes to next of settings Textview. it should be adjust when size increased.
small size
big size
Code
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#android:color/darker_gray" >
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Settings"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:textColor="#android:color/holo_orange_dark"
android:textSize="16.0sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="hiiiiiiiiiiiii StackOverflower!!!!!!!!!!!"
android:padding="4dp"
android:gravity="center"
android:layout_toLeftOf="#+id/txtBack"
android:textColor="#android:color/white"
android:textSize="19sp" />
</RelativeLayout>
Because you are using match_parent for those two TextViews, that is why they will being overlapped, based on your code, you can try to add a fix padding for the second TextView. For example, we consider the width of the first TextView's text "Settings" is 100dp, so we can change the code as below.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#android:color/darker_gray" >
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Settings"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:textColor="#android:color/holo_orange_dark"
android:textSize="16.0sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="hiiiiiiiiiiiii StackOverflower!!!!!!!!!!!"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingLeft="100dp"
android:paddingRight="100dp"
android:gravity="center"
android:layout_toLeftOf="#+id/txtBack"
android:textColor="#android:color/white"
android:textSize="19sp" />
</RelativeLayout>
set id to your first TextView and then make second TextView toRightOf first one.
Like This
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#android:color/darker_gray" >
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Settings"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:textColor="#android:color/holo_orange_dark"
android:textSize="16.0sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="#id/textview1"
android:text="hiiiiiiiiiiiii StackOverflower!!!!!!!!!!!"
android:padding="4dp"
android:gravity="center"
android:layout_toLeftOf="#+id/txtBack"
android:textColor="#android:color/white"
android:textSize="19sp" />
</RelativeLayout>
I hope this will help.
Try this,
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#android:color/darker_gray" >
<TextView
android:id="#+id/txtSetting"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Settings"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:textColor="#android:color/holo_orange_dark"
android:textSize="16.0sp" />
<TextView
android:layout_toRightOf="#+id/txtSetting"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="hiiiiiiiiiiiii StackOverflower!!!!!!!!!!!"
android:padding="4dp"
android:gravity="center"
android:layout_toLeftOf="#+id/txtBack"
android:textColor="#android:color/white"
android:textSize="19sp" />
</RelativeLayout>
Use layout_toLeftOf ,alignParentLeft and alignParentRight
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Settings"
android:id="#+id/txtBack"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/selectaccount"
android:textColor="#android:color/holo_orange_dark"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hiiiiiiiiiiiii StackOverflower!!!!!!!!!!!"
android:padding="4dp"
android:gravity="center"
android:layout_alignParentRight="true"
android:textColor="#android:color/white"
android:textAppearance="?android:attr/textAppearanceMedium" />
Just Replace Your Code By Below:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#android:color/darker_gray" >
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Settings"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:textColor="#android:color/holo_orange_dark"
android:textSize="16.0sp"
android:id="#+id/txtSettings" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="hiiiiiiiiiiiii StackOverflower!!!!!!!!!!!"
android:padding="4dp"
android:gravity="center"
android:layout_toRightOf="#+id/txtSettings"
android:layout_toLeftOf="#+id/txtBack"
android:textColor="#android:color/white"
android:textSize="19sp" />
</RelativeLayout>
change second textview to this:
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="hiiiiiiiiiiiii StackOverflower!!!!!!!!!!!"
android:padding="4dp"
android:gravity="center"
android:layout_toRightOf="#+id/firstTextview"
android:textColor="#android:color/white"
android:textSize="19sp" />
Related
Please view the image below:
The first image is the layout I did and it show normally on my device and another test devices. The second image is the layout showed on my friend device, it is reversed. I do not know why, and it just happened on few devices.
This is my layout code on xml.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:auto="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.ComposeSmsActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar_action" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="#dimen/padding_5">
<com.hnib.smslater.views.FlowLayout
android:id="#+id/layout_name_recipient"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_10"
android:fontFamily="sans-serif-light"
android:orientation="horizontal">
</com.hnib.smslater.views.FlowLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/padding_10">
<com.hnib.smslater.views.ClearableAutoContactCompleteTextView
android:id="#+id/et_recipient"
android:layout_width="#dimen/width_et_contact"
android:layout_height="#dimen/height_et_default"
android:layout_centerVertical="true"
android:layout_marginTop="#dimen/margin_10"
android:background="#drawable/drawable_radius_gray_gray"
android:fontFamily="sans-serif-light"
android:hint="#string/to_"
android:imeOptions="actionDone"
android:padding="#dimen/padding_5"
android:textColorHint="#color/gray"
android:textSize="18sp"
android:textStyle="bold"
auto:displayPhotoIfAvailable="false"
auto:styleOfTypedLetters="bold"
auto:typeOfData="phone"
auto:typedLettersHaveDifferentStyle="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_5"
android:layout_marginTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:fontFamily="sans-serif-light"
android:text="#string/message"
android:textColor="#color/gray"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_message_length"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:text="160/1" />
</RelativeLayout>
<com.hnib.smslater.views.ActionEditText
android:id="#+id/et_text_content"
android:layout_width="match_parent"
android:layout_height="#dimen/height_et_big"
android:layout_marginLeft="#dimen/margin_5"
android:background="#drawable/drawable_radius_gray_gray"
android:ems="10"
android:fontFamily="sans-serif-light"
android:gravity="top"
android:inputType="textMultiLine"
android:maxLines="10"
android:padding="#dimen/padding_5"
android:scrollbars="vertical" />
<RelativeLayout
android:id="#+id/layout_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="#dimen/padding_10"
android:showDividers="middle">
<TextView
android:id="#+id/tv_title_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#drawable/drawable_radius_acent_gray"
android:fontFamily="sans-serif-light"
android:padding="#dimen/padding_5"
android:text="#string/time"
android:textAllCaps="true" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/tv_title_time"
android:divider="?android:attr/dividerVertical"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="#dimen/padding_10"
android:showDividers="middle">
<TextView
android:id="#+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/selector_textview"
android:fontFamily="sans-serif-light"
android:gravity="center_horizontal"
android:text="12/06/2016"
android:textColor="#color/gray"
android:textSize="27sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/selector_textview"
android:fontFamily="sans-serif-light"
android:gravity="center_horizontal"
android:text="09:10"
android:textColor="#color/gray"
android:textSize="27sp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="#dimen/padding_10">
<TextView
android:id="#+id/tv_title_repeat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="30dp"
android:background="#drawable/drawable_radius_acent_gray"
android:fontFamily="sans-serif-light"
android:padding="#dimen/padding_5"
android:text="#string/repeat"
android:textAllCaps="true" />
<Spinner
android:id="#+id/spinner_repeat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Spinner>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_choose_sim"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="#dimen/padding_10">
<TextView
android:id="#+id/title_choose_sim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="30dp"
android:background="#drawable/drawable_radius_acent_gray"
android:fontFamily="sans-serif-light"
android:padding="#dimen/padding_5"
android:text="#string/choose_sim"
android:textAllCaps="true" />
<Spinner
android:id="#+id/spinner_choose_sim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Spinner>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_confirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="#dimen/padding_10">
<TextView
android:id="#+id/tv_title_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:background="#drawable/drawable_radius_acent_gray"
android:fontFamily="sans-serif-light"
android:padding="#dimen/padding_5"
android:text="#string/ask_before_send"
android:textAllCaps="true" />
<CheckBox
android:id="#+id/checkbox_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/tv_title_confirm" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Please have a help on this issue. Thanks.
The language on your friend's phone is probably different from yours, leading to the app giving a read from right to left, rather than your left to right. Does your friend have his phone's settings on language set to Hebrew or Arabic?
Edit: please take note of the answers below mine, those are the viable options for your friend's phone, besides for changing the language of course.
You should remove android:supportsRtl="true"
from the <application> element in your AndroidManifest.xml file.
You should ADD : android:supportRTL="false"
In the manifest
Searched and found many solutions but nothing seems to be working in my case.
I have 2 TextViews, side by side. This is what i am getting in preview.
and I want this
I have written following code, but its not giving me desired output.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<TextView
android:id="#+id/tvContactsHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="18sp"
android:paddingRight="10dp"
android:text="Heading "
android:textStyle="bold"
android:fontFamily="sans-serif-regular"
/>
<TextView
android:id="#+id/tvContactsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="18sp"
android:text="Text "
android:textStyle="normal"
android:fontFamily="sans-serif-regular"
/>
</LinearLayout>
</RelativeLayout>
If i use android:layout_gravity to left or right, it takes the whole text to left or right side.. I want to put both text in center, one starts from right corner and other starts from left corner.
Kindly guide me.
I have checked below XML file by myself ..
just put android:layout_weight="1" for both TextView and make android:layout_width="0dp" for both TextView..
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="sans-serif-regular"
android:gravity="right"
android:paddingRight="10dp"
android:text="this code is working fine for me"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="sans-serif-regular"
android:gravity="left"
android:text="this is right side of the layout"
android:textSize="18sp"
android:textStyle="normal" />
</LinearLayout>
</RelativeLayout>
hope it will help u :)
You have to give match_parent width to LinearLayout.
Use this code.
<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_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="#+id/tvContactsHeading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="18sp"
android:text="HeadingShort"
android:textStyle="bold"
android:paddingRight="10dp"
android:layout_weight="0.5"
android:fontFamily="sans-serif-regular"
/>
<TextView
android:id="#+id/tvContactsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textSize="18sp"
android:text="TextShort"
android:textStyle="normal"
android:layout_weight="0.5"
android:fontFamily="sans-serif-regular"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal"
android:layout_weight="1.0"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/tvContactsHeading2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="18sp"
android:text="HeadingLongggg"
android:textStyle="bold"
android:paddingRight="10dp"
android:layout_weight="0.5"
android:fontFamily="sans-serif-regular"
/>
<TextView
android:id="#+id/tvContactsText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textSize="18sp"
android:text="HeadingLoggg"
android:textStyle="normal"
android:layout_weight="0.5"
android:fontFamily="sans-serif-regular"
/>
</LinearLayout>
</RelativeLayout>
Your Output is
<TextView
android:id="#+id/tvContactsHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:paddingRight="10dp"
android:text="Heading "
android:textStyle="bold"
android:gravity="right|center_vertical|center_horizontal"
android:fontFamily="sans-serif-regular"
/>
<TextView
android:id="#+id/tvContactsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Text "
android:textStyle="normal"
android:gravity="center|center_vertical|center_horizontal"
android:fontFamily="sans-serif-regular"
/>
You can add android:layout_weight=1 for each text and then change the gravity as you like
<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_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<TextView
android:id="#+id/tvContactsHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="18sp"
android:paddingRight="10dp"
android:text="Heading "
android:textStyle="bold"
android:fontFamily="sans-serif-regular"
android:layout_weight="1"
/>
<TextView
android:id="#+id/tvContactsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="18sp"
android:text="Text "
android:textStyle="normal"
android:fontFamily="sans-serif-regular"
android:layout_weight="1"
/>
</LinearLayout>
Also you can do that with relative layout which will be better
Set the layout_widthto match_parentand then apply your desired gravity.
The LinearLayoutdoes not allow you to place items on the right. So you have to set the TextViewto a full width, so you can apply the gravity for it's contents.
The other options is, that you could replace LinearLayoutwith FrameLayout.
The FrameLayoutallows absolute positioning, the LinearLayoutdoes not, which would not require to set the TextViewto a full width.
I'm trying to align text inside textview to the center (both vertical and horizontal).
Altought the vertical alignment working properlly in the Android Studio preview, it fails on the emulator.
The design:
The android studio preview:
The emulator:
The code:
<RelativeLayout
android:id="#+id/teamsBox"
android:layout_width="match_parent"
android:layout_height="185dp">
<LinearLayout
android:layout_width="154dp"
android:layout_height="wrap_content"
android:background="#drawable/team_bg"
android:padding="6dp"
android:layout_alignParentLeft="true"
android:orientation="vertical">
<EditText
android:id="#+id/teamOneName"
android:layout_width="143dp"
android:layout_height="42dp"
android:text="HOME"
android:textColor="#color/my_white"
android:background="#color/my_transparent"
android:textSize="23sp"
android:singleLine="true"
android:gravity="center"/>
<TextView
android:id="#+id/teamOneScore"
android:layout_width="143dp"
android:layout_height="132dp"
android:text="3"
android:textColor="#color/my_green"
android:textSize="127sp"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="154dp"
android:layout_height="match_parent"
android:background="#drawable/team_bg"
android:padding="6dp"
android:layout_alignParentRight="true"
android:orientation="vertical">
<EditText
android:id="#+id/teamTwoName"
android:layout_width="match_parent"
android:layout_height="42dp"
android:text="AWAY"
android:textColor="#color/my_white"
android:background="#color/my_transparent"
android:textSize="23sp"
android:singleLine="true"
android:gravity="center"/>
<TextView
android:id="#+id/teamTwoScore"
android:layout_width="fill_parent"
android:layout_height="132dp"
android:text="1"
android:textColor="#color/my_green"
android:textSize="127sp"
android:gravity="center"
android:layout_gravity="center"/>
</LinearLayout>
</RelativeLayout>
Edit: I've changed to layout according to the answers, but the bug is still happening.
This is my new layout:
<RelativeLayout
android:id="#+id/teamsBox"
android:layout_width="match_parent"
android:layout_height="185dp">
<LinearLayout
android:layout_width="154dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="#drawable/team_bg"
android:orientation="vertical"
android:padding="6dp" >
<EditText
android:id="#+id/teamOneName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="HOME"
android:textColor="#color/my_white"
android:background="#color/my_transparent"
android:textSize="23sp"
android:singleLine="true"
android:padding="8dp"
android:gravity="center"/>
<TextView
android:id="#+id/teamOneScore"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="3"
android:textColor="#color/my_green"
android:textSize="127sp"
android:gravity="center_vertical|center_horizontal"/>
</LinearLayout>
<LinearLayout
android:layout_width="154dp"
android:layout_height="match_parent"
android:background="#drawable/team_bg"
android:padding="6dp"
android:layout_alignParentRight="true"
android:orientation="vertical">
<EditText
android:id="#+id/teamTwoName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AWAY"
android:textColor="#color/my_white"
android:background="#color/my_transparent"
android:textSize="23sp"
android:singleLine="true"
android:padding="8dp"
android:gravity="center"/>
<TextView
android:id="#+id/teamTwoScore"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="1"
android:textColor="#color/my_green"
android:textSize="127sp"
android:gravity="center"
android:layout_gravity="center"/>
</LinearLayout>
</RelativeLayout>
To problem is in the TextView itself, the large size of the text is not calculated by the gravity attribute.
Try adding this attribute to your text view android:includeFontPadding="false"
set your textView's android:gravity to center_vertical | center_horizontal
<TextView
android:id="#+id/teamOneScore"
android:layout_width="143dp"
android:layout_height="132dp"
android:text="3"
android:textColor="#color/my_green"
android:textSize="127sp"
android:gravity="center_vertical | center_horizontal" />
Remove hard coded width and height and use weight.Try the following data
<RelativeLayout
android:id="#+id/teamsBox"
android:layout_width="match_parent"
android:layout_height="185dp" >
<LinearLayout
android:layout_width="154dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#drawable/button_background"
android:orientation="vertical"
android:padding="6dp" >
<EditText
android:id="#+id/teamOneName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#123456"
android:gravity="center"
android:singleLine="true"
android:text="HOME"
android:textSize="23sp" />
<TextView
android:id="#+id/teamOneScore"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center_vertical|center_horizontal"
android:text="3"
android:layout_weight="1"
android:textSize="127sp" />
</LinearLayout>
<LinearLayout
android:layout_width="154dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="#drawable/button_background"
android:orientation="vertical"
android:padding="6dp" >
<EditText
android:id="#+id/teamTwoName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#123456"
android:gravity="center"
android:singleLine="true"
android:text="AWAY"
android:textSize="23sp" />
<TextView
android:id="#+id/teamTwoScore"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:gravity="center_vertical|center_horizontal"
android:text="1"
android:layout_weight="1"
android:textSize="127sp" />
</LinearLayout>
</RelativeLayout>
Hope this works
try this it may help you,
<?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="wrap_content"
android:background="#android:color/holo_green_light" >
<LinearLayout
android:layout_width="154dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="vertical"
android:padding="6dp" >
<EditText
android:id="#+id/teamOneName"
android:layout_width="143dp"
android:layout_height="42dp"
android:background="#android:color/holo_green_dark"
android:gravity="center"
android:singleLine="true"
android:text="HOME"
android:textColor="#android:color/white"
android:textSize="23sp" />
<TextView
android:id="#+id/teamOneScore"
android:layout_width="143dp"
android:layout_height="132dp"
android:gravity="center"
android:text="3"
android:background="#android:color/white"
android:textSize="127sp" />
</LinearLayout>
<LinearLayout
android:layout_width="154dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="vertical"
android:padding="6dp" >
<EditText
android:id="#+id/teamTwoName"
android:layout_width="match_parent"
android:layout_height="42dp"
android:background="#android:color/holo_green_dark"
android:gravity="center"
android:singleLine="true"
android:text="AWAY"
android:textColor="#android:color/white"
android:textSize="23sp" />
<TextView
android:id="#+id/teamTwoScore"
android:layout_width="fill_parent"
android:layout_height="132dp"
android:layout_gravity="center"
android:gravity="center"
android:text="1"
android:background="#android:color/white"
android:textSize="127sp" />
</LinearLayout>
</RelativeLayout>
Just use match_parent as the height of the textview.
Your linear layout which is having the edit text and one text view height is lesser than you have given height to its children. Please calculate height for the edit text and text view and accordingly adjust height of your linear layout.
Here You just need to give wrap_content to you text view and .
1. change in text view
android:layout_height="132dp"
To
android:layout_height="wrap_content"
2. Increase you linear layout height to
android:layout_width="184dp"
3. remove below pading tag from your linear layout
android:padding="6dp"
it will fix your issue.
i've a strange problem when i set android:layout_width="fill_parent" in my Spinner:
the clickable area is reduced to a line (red square) and only pressing on this line is possibile show the elements of the Spinner:
if i use android:layout_width="wrap_content" i obtain the correct area:
i would like the same thing using "fill_parent"
The elements of the Spinner are correctly visualized.. The only problem is clicking on the Spinner.
Which is the possible problem?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#040404"
android:gravity="center"
android:paddingTop="2dp"
android:weightSum="4" >
<TextView
android:id="#+id/mpp_movimento_lbl"
android:background="#drawable/selector_black_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/freccia_verde"
android:gravity="center"
android:text="#string/Movimento"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="17sp" />
<TextView
android:id="#+id/mpp_eccesso_lbl"
android:background="#drawable/selector_black_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/freccia_rossa"
android:gravity="center"
android:text="#string/Eccesso"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="17sp" />
<TextView
android:id="#+id/mpp_fermo_lbl"
android:background="#drawable/selector_black_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/freccia_grigia"
android:gravity="center"
android:text="#string/Fermo"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="17sp" />
<TextView
android:id="#+id/mpp_ripristina_lbl"
android:background="#drawable/selector_black_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/ripristina_mappa_40x40"
android:gravity="center"
android:text="#string/Ripristina"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="17sp" />
</LinearLayout>
<TextView
android:id="#+id/mpp_automezzi_visualizzati_lbl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/black"
android:gravity="center"
android:paddingTop="5dp"
android:text="#string/AutomezziVisualizzati"
android:textColor="#color/white"
android:textSize="17sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:paddingTop="5dp" >
<FrameLayout
android:id="#+id/mpp_spinner_frame_fly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/mpp_cerca_btn" >
<Spinner
android:id="#+id/mpp_spinner_spn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textSize="17sp" />
</FrameLayout>
<ImageButton
android:id="#+id/mpp_cerca_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:background="#drawable/selector_white_btn"
android:contentDescription="#string/DescrizioneCerca"
android:gravity="center"
android:onClick="doCerca"
android:src="#drawable/cerca" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#040404"
android:gravity="center" >
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="#+id/mpp_mappa_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
Try setting your Spinner's parent's height to match_parent. And also do you really need such layout? There is no need to place spinner in FrameLayout, try setting spinners's weight to 1 and replace RelativeLayout with LinearLayout
i am trying to implemnt a app in i wrote code to draw APP Menu .In my application Menu is drawing at top_center of the layout for all resolution as shown in below images.
But i need Buttons at horizontal&vertical center of layout for all resolutions and screens.
Currently i am using below code.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/myLinear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2E9AFE"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Choose an Option"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white"
android:textSize="25dp"
android:textStyle="bold"
android:typeface="sans" />
"
<Button
android:id="#+id/bDefSms"
android:layout_width="256dp"
android:layout_height="64dp"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/blackbutton"
android:drawableLeft="#drawable/sms"
android:paddingBottom="20dp"
android:text="AAA"
android:textColor="#android:color/white"
android:textSize="32dp"
android:textStyle="bold" />
<Button
android:id="#+id/bSMS"
android:layout_width="256dp"
android:layout_height="64dp"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:background="#drawable/blackbutton"
android:drawableLeft="#drawable/defsms"
android:text="BBB"
android:textColor="#android:color/white"
android:textSize="32dp"
android:textStyle="bold" />
<Button
android:id="#+id/bMMS"
android:layout_width="256dp"
android:layout_height="64dp"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:background="#drawable/blackbutton"
android:drawableLeft="#drawable/mms"
android:text="CCC"
android:textColor="#android:color/white"
android:textSize="32dp"
android:textStyle="bold" />
<Button
android:id="#+id/bMail"
android:layout_width="256dp"
android:layout_height="64dp"
android:layout_gravity="center"
android:background="#drawable/blackbutton"
android:drawableLeft="#drawable/email"
android:text="DDD"
android:textColor="#android:color/white"
android:textSize="32dp"
android:textStyle="bold" />
</LinearLayout>
Please help me.
just add one line to your linearlayout:
android:gravity="center"
wHey why don't you use RelativeLayout as a root like this and use attribute layout_centerHorizontal and layout_centerVertical to true:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/myLinear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#2E9AFE"
android:orientation="vertical"
tools:context=".MainActivity" >
</LinearLayout>
I hope this will help.