how to align controls in android linear layout - android

I am using android studio to design a dashboard. Now I am facing the issue that I have a linear layout where I want 2 buttons in each row, with one button on the left and other at right of the screen. My xml is like this:
<LinearLayout style="#style/ActivityBody"
android:orientation="vertical"
>
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dip"
android:layout_gravity="left"
android:layout_marginLeft="20dp"
>
<Button
android:id="#+id/btnMaterialIssue"
style="#style/DashboardButton"
android:drawableTop="#drawable/materialissue"
android:text="Material Issue"
android:onClick="onGol"
android:layout_gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnWorkCompletion"
style="#style/DashboardButton"
android:drawableTop="#drawable/workcompletion"
android:text="Work Completion"
android:onClick="onGol"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
My style file is like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="Theme" parent="android:Theme"></style>
<style name="Theme.D1t" parent="android:style/Theme.Light">
<item name="android:windowNoTitle">false</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="Theme.D1" parent="android:style/Theme.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="Theme.tranlucent" parent="android:style/Theme.Translucent">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="Home">
<item name="android:layout_gravity">center_vertical</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">0</item>
<item name="android:background">#fff</item>
</style>
<style name="HomeText">
<item name="android:layout_gravity">center_vertical</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">0</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:textSize"> 18sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/foreground</item>
</style>
<style name="TitleBar">
<item name="android:id">#id/title_container</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">45dip</item>
<item name="android:orientation">horizontal</item>
<item name="android:background">#color/title_background</item>
</style>
<style name="TitleBarOperation">
<item name="android:layout_width">45dip</item>
<item name="android:layout_height">fill_parent</item>
</style>
<style name="TitleBarLogo">
<item name="android:id">#id/title_logo</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">fill_parent</item>
</style>
<style name="TitleBarText">
<item name="android:id">#id/title_text</item>
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textSize">18sp</item>
<item name="android:paddingLeft">12dip</item>
<item name="android:paddingRight">12dip</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/title_text</item>
<item name="android:singleLine">true</item>
<item name="android:ellipsize">end</item>
</style>
<style name="TextBody">
<item name="android:textSize">15sp</item>
<item name="android:lineSpacingMultiplier">1.1</item>
<item name="android:textColor">#color/textBody</item>
<item name="android:textStyle">bold</item>
</style>
<style name="ActivityBody">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="DashboardButton">
<item name="android:layout_gravity">center_vertical</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:drawablePadding">2dp</item>
<item name="android:textSize">9dp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#fff</item>
<item name="android:background">#null</item>
</style>
</resources

you have to use android:layout_weight
to use layout_weight you want to set layout_width as "0dp"
android:layout_width="0dp"
android:layout_weight="1"
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dip"
android:layout_gravity="left"
android:layout_marginLeft="20dp"
>
<Button
android:id="#+id/btnMaterialIssue"
style="#style/DashboardButton"
android:drawableTop="#drawable/materialissue"
android:text="Material Issue"
android:onClick="onGol"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnWorkCompletion"
style="#style/DashboardButton"
android:drawableTop="#drawable/workcompletion"
android:text="Work Completion"
android:onClick="onGol"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>

what you can do is to use the relative layout and align them to left and right
below is the code
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dip"
android:layout_gravity="left"
android:layout_marginLeft="20dp">
<Button
android:id="#+id/btnMaterialIssue"
style="#style/DashboardButton"
android:drawableTop="#drawable/materialissue"
android:text="Material Issue"
android:onClick="onGol"
android:layout_alignParentRight="true"
android:layout_gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnWorkCompletion"
android:layout_alignParentLeft="true"
style="#style/DashboardButton"
android:drawableTop="#drawable/workcompletion"
android:text="Work Completion"
android:onClick="onGol"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>

Option:
Use margins to the left of right button and to the right of the left button.
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dip"
android:layout_gravity="left"
android:layout_marginLeft="20dp"
>
<Button
android:id="#+id/btnMaterialIssue"
style="#style/DashboardButton"
android:drawableTop="#drawable/materialissue"
android:text="Material Issue"
android:onClick="onGol"
layout_marginRight="20dp"
android:layout_gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnWorkCompletion"
style="#style/DashboardButton"
android:drawableTop="#drawable/workcompletion"
android:text="Work Completion"
android:onClick="onGol"
layout_marginLeft="20dp"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Option:
place something (another view (Linearlayout)) in the middle, between the buttons.
Option:
Try to play with layout_weight
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="New Button"
android:layout_weight="1"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="New Button"
android:layout_weight="1"/>
</LinearLayout>

Add all linearlayout in relativelayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:orientation="horizontal" >
And in linearlayout or button add android:layout_alignParentRight="true"
<Button
android:id="#+id/btnAddExpense"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="15dp"
android:background="#drawable/stitch_button"
android:text="#string/add" />

Related

Radio Button set custom drawable not working

I have used the radio button and set a custom drawable for a check/uncheck
I want to this
but my current output is this
Radio button XML code
<RadioGroup
android:id="#+id/segmented2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="6dp"
android:layout_weight="1"
android:baselineAligned="false"
android:orientation="horizontal">
<RadioButton
android:id="#+id/colorRadioButton"
style="#style/RadioButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:checked="true"
android:text="#string/color_color" />
<RadioButton
android:id="#+id/gradientRadioButton"
style="#style/RadioButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:checked="false"
android:text="#string/color_gradient"
android:visibility="visible" />
</RadioGroup>
style/RadioButton
<style name="RadioButton" parent="Base.Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:gravity">center_vertical|center</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:paddingRight">20dp</item>
<item name="android:background">#null</item>
<item name="android:button">#drawable/radio_checked_unchecked</item>
<item name="android:minWidth">70dp</item>
<item name="android:minHeight">35dp</item>
</style>
drawable/radio_checked_unchecked.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/radio_checked" android:state_checked="true"/>
<item android:drawable="#drawable/radio_unchecked"/>
</selector>
Firstly, you need to change the android:orientation from horizontal to vertical. You can also use fixed layout width and height if you use larger or unscalable custom drawables.
So, your updated RadioGroup codebase will be like below:
<RadioGroup
android:id="#+id/segmented2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_margin="6dp"
android:layout_weight="1"
android:baselineAligned="false"
android:orientation="vertical">
<RadioButton
android:id="#+id/colorRadioButton"
style="#style/RadioButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:checked="true"
android:text="#string/color_color" />
<RadioButton
android:id="#+id/gradientRadioButton"
style="#style/RadioButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:checked="false"
android:text="#string/color_gradient"
android:visibility="visible" />
</RadioGroup>
Also, button should be set to #null, and the radioGroup background should be your custom drawable.
So, your updated style codebase will be like below:
<style name="RadioButton" parent="Base.Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:gravity">center_vertical|center</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:paddingRight">20dp</item>
<item name="android:background">#drawable/radio_checked_unchecked</item>
<item name="android:button">#null</item>
<item name="android:minWidth">70dp</item>
<item name="android:minHeight">35dp</item>
</style>
I think you need to use this:
<item name="android:background">#drawable/radio_checked_unchecked</item>
<item name="android:button">#null</item>
instead of this:
<item name="android:background">#null</item>
<item name="android:button">#drawable/radio_checked_unchecked</item>
in your style.
I got an idea from the given answer and I found a solution to my question
Change
<RadioButton
android:id="#+id/colorRadioButton"
style="#style/RadioButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:checked="true"
android:text="#string/color_color" />
To
<RadioButton
android:id="#+id/autoRadioButton"
style="#style/RadioButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:checked="false"
android:text="#string/auto"
android:drawablePadding="#dimen/_10sdp"
android:drawableStart="#drawable/radio_checked_unchecked"/>
set android:drawableStart to set custom drawable and set button="#null"
style
<style name="RadioButton" parent="Base.Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:textColor">#color/bvc_sticker_button_text_color</item>
<item name="android:gravity">center_vertical|center</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:paddingRight">20dp</item>
<item name="android:background">#null</item>
<item name="android:button">#null</item>
<item name="android:minWidth">70dp</item>
<item name="android:minHeight">35dp</item>
<item name="fontFamily">#font/inter_medium</item>
</style>
use the above code and get output like this

I need change the color to border of the check box,Because it is in white color

I have check box in my contacts list to select that. But check box is in white color,it is not visible...So i need to change that border to black color...Please help me to change the code
This is my layout code
<LinearLayout 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:divider="?android:dividerVertical"
android:showDividers="middle"
android:dividerPadding="5dp"
tools:context=".MainActivity" >
<ImageButton
android:id="#+id/image"
android:layout_width="#dimen/contact_image"
android:layout_height="50dp"
android:src="#drawable/contacts_image" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:clickable="false"
android:focusable="true"
android:orientation="vertical" >
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:paddingTop="1dp"
android:textColor="#color/black"
android:textSize="18sp"
/>
<TextView
android:id="#+id/mobile_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="15sp"
android:paddingLeft="5dp"
android:paddingRight="0dp"
/>
</LinearLayout>
<CheckBox
android:id="#+id/check_box"
android:layout_width="#dimen/check_box_width"
android:layout_height="50dp"
android:visibility="visible"
android:clickable="true"/>
</LinearLayout>
This is my style.xml code
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#color/scandal</item>
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
<style name="ActionBarCompat">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">50dp</item>
<item name="android:orientation">horizontal</item>
</style>
<style name="DashboardButton">
<item name="android:layout_gravity">center_vertical</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:drawablePadding">2dp</item>
<item name="android:textSize">16dp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#ff29549f</item>
<item name="android:background">#null</item>
</style>
<style name="FooterBar">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">40dp</item>
<item name="android:orientation">horizontal</item>
<item name="android:background">#dedede</item>
</style>
<style name="Divider">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
<item name="android:background">?android:attr/listDivider</item>
</style>
</resources>
instead changing the default in style xml file. do this.
create this your_custom.xml file and and save it in drawable folder
your_custom.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/unselected" android:state_checked="false"><color android:textColor="#your_color" />
</item>
<item android:drawable="#drawable/selected" android:state_checked="true"><color android:textColor="#your_color" />
</item>
<item android:drawable="#drawable/uncheck"></item>
<!-- default -->
</selector>
you will have to create three images for checkbox display
1.selected
2.unselect
3.uncheck
after all this done set attribute to your checkbox in layout
android:button="#drawable/your_custom"

Activity with theme Dialog's custom title height

I have an activity with the following theme
<style name="CustomDialogTitle" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/PauseDialogTitle</item>
</style>
<style name="PauseDialogTitle" parent="#android:style/TextAppearance.DialogWindowTitle">
<item name="android:gravity">center_horizontal</item>
<item name="android:windowTitleSize">50dip</item>
<item name="android:height">70dip</item>
<item name="android:maxLines">2</item>
<item name="android:singleLine">false</item>
</style>
<style name="DialogWindowTitle">
<item name="android:textAppearance">#android:style/TextAppearance.DialogWindowTitle</item>
</style>
and this is the custom title layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dip"
android:orientation="vertical" >
<TextView
android:id="#+id/first_line_title_text"
style="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:text="first line" />
<TextView
android:id="#+id/second_line_title_text"
style="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:text="second line" />
I can only see one line of the title layout
What's causing the title to show only one line with fixed height ?
although i'm specifying height in the layout and style

TextView ellipsize not work inside RelativeLayout

I can't understand why my textview is not ellipsized. Thank you for any help.
I have this layout:
<?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="65dp"
android:background="#drawable/dash_whiteplate"
android:minHeight="#dimen/info_activity_list_item_height"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:weightSum="1.0" >
<RelativeLayout style="#style/ItemFlightRouteLayout" >
<ImageView
android:id="#+id/routImageTop"
style="#style/ItemFlightRouteArrow"
android:src="#drawable/icon_arrowup_normal" />
<TextView
android:id="#+id/routAiroportFrom"
style="#style/ItemFlightRouteAirportName"
android:layout_toLeftOf="#+id/topDescription"
android:layout_toRightOf="#+id/routImageTop"
android:textAppearance="#style/ItemFlightRouteAirportName"
android:text="askdjflsfksdfasdfdfsfdsfsdfsfdsdfsfd" />
<RelativeLayout
android:id="#+id/topDescription"
style="#style/ItemFlightRouteDescriptionLayout" >
<View
android:id="#+id/verticalDivider"
style="#style/ItemFlightRouteSeparator"
android:layout_toLeftOf="#+id/txt_time" />
<RelativeLayout
android:id="#+id/txt_time"
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_toLeftOf="#+id/verticalDivider2" >
<TextView
android:id="#+id/timeDep"
style="#style/ItemFlightRouteText"
android:textColor="#color/statusLanded" />
</RelativeLayout>
<View
android:id="#+id/verticalDivider2"
style="#style/ItemFlightRouteSeparator"
android:layout_toLeftOf="#+id/txt_gate" />
<RelativeLayout
android:id="#+id/txt_gate"
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true" >
<TextView
android:id="#+id/desciptionTop"
style="#style/ItemFlightRouteText" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#color/grey" />
<RelativeLayout style="#style/ItemFlightRouteLayout" >
<ImageView
android:id="#+id/routImageBottom"
style="#style/ItemFlightRouteArrow"
android:src="#drawable/icon_arrowdown_normal" />
<TextView
android:id="#+id/routAiroportTo"
style="#style/ItemFlightRouteAirportName"
android:layout_toLeftOf="#+id/bottomDescription"
android:layout_toRightOf="#+id/routImageBottom"
android:textAppearance="#style/ItemFlightRouteAirportName" />
<RelativeLayout
android:id="#+id/bottomDescription"
style="#style/ItemFlightRouteDescriptionLayout" >
<View
android:id="#+id/verticalDivider3"
style="#style/ItemFlightRouteSeparator"
android:layout_toLeftOf="#+id/txt_time2" />
<RelativeLayout
android:id="#+id/txt_time2"
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_toLeftOf="#+id/verticalDivider4" >
<TextView
android:id="#+id/timeArr"
style="#style/ItemFlightRouteText" />
</RelativeLayout>
<View
android:id="#+id/verticalDivider4"
style="#style/ItemFlightRouteSeparator"
android:layout_toLeftOf="#+id/txt_gate2" />
<RelativeLayout
android:id="#+id/txt_gate2"
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true" >
<TextView
android:id="#+id/desciptionBottom"
style="#style/ItemFlightRouteText" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
and styles:
<style name="ItemFlightRouteLayout">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">0.5</item>
<item name="android:weightSum">1.0</item>
</style>
<style name="ItemFlightRouteArrow">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_alignParentLeft">true</item>
<item name="android:layout_centerInParent">true</item>
<item name="android:layout_marginLeft">5dp</item>
</style>
<style name="ItemFlightRouteAirportName">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_centerVertical">true</item>
<item name="android:layout_margin">5dp</item>
<item name="android:ellipsize">marquee</item>
<item name="android:padding">2dp</item>
<item name="android:singleLine">true</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">14sp</item>
</style>
<style name="ItemFlightRouteDescriptionLayout">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_alignParentRight">true</item>
<item name="android:layout_gravity">right</item>
</style>
<style name="ItemFlightRouteSeparator">
<item name="android:layout_width">1dp</item>
<item name="android:layout_height">22dp</item>
<item name="android:layout_centerVertical">true</item>
<item name="android:layout_marginBottom">5dp</item>
<item name="android:layout_marginTop">5dp</item>
<item name="android:background">#color/grey</item>
</style>
<style name="ItemFlightRouteText">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_centerVertical">true</item>
<item name="android:layout_margin">5dp</item>
<item name="android:gravity">center</item>
</style>
Finally I've got it!
What I've done: moved routImageTop and routAiroportFrom to LinearLayout, aligned it at parent left and set android:layout_toLeftOf="#+id/topDescription"
Now it works.
Add in your Xml
<item name="android:marqueeRepeatLimit">marquee_forever</item>
in Activity
your_textview.setSelected(true);
your_textview.setSingleLine(true);
your_textview.setEllipsize(TruncateAt.MARQUEE);
I think you can put these values in Xml too...
Hope this help
The TextView needs focus to make the marquee scroll in a TextView. Have you tried using either selected_state, requestFocus, or setSelected to set focus to the TextView?
Make a Scrolling Marquee, using scrollHorizontally, in a TextView
Deprecated: Make a Scrolling Marquee, using singleLine, in a TextView

How can I modify this theme to prevent Button text from overlapping the TextView text?

I have a layout that appears as follows when there is no style applied to it (other than hard-coded styles, e.g. colour & font that apply to both instances):
But it appears like this when I apply a style:
The layout is defined as:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/txtBlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[Block Name]"
android:textSize="15sp"
android:layout_gravity="center" />
<Button
android:gravity="left|bottom"
android:background="#null"
android:text="[Block Status]"
android:id="#+id/btnStatus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/imgAlarm"
android:layout_alignParentLeft="true" />
<ImageButton
android:id="#id/imgAlarm"
android:background="#null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/alarm"
android:layout_centerVertical="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
and my styles.xml is defined as:
<resources>
<!-- Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices. -->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!-- Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here. -->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="FullscreenTheme" parent="android:Theme.NoTitleBar">
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#null</item>
</style>
<style name="ButtonBar">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingRight">2dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:background">#android:drawable/bottom_bar</item>
</style>
<style name="ButtonBarButton" />
<style name="keypad_button" >
<item name="android:layout_width" >fill_parent</item>
<item name="android:layout_height" >wrap_content</item>
<item name="android:textColor" >#ffffff</item>
<item name="android:gravity" >center</item>
<item name="android:textSize" >15sp</item>
<item name="android:width">65dp</item>
</style>
<!--<style name="CustomTheme" parent="#android:style/Theme">
<item name="android:tabWidgetStyle">#style/CustomTabWidget</item>
</style>
<style name="CustomTabWidget" parent="#android:style/Widget.TabWidget">
<item name="android:textAppearance">#style/CustomTabWidgetText</item>
</style>
<style name="CustomTabWidgetText" parent="#android:style/TextAppearance.Widget.TabWidget">
<item name="android:textSize">50sp</item>
<item name="android:textStyle">bold</item>
</style>-->
</resources>
What do I need to do to prevent the text from overlapping?
Change youe xml like this:
<Button
android:gravity="left|bottom"
android:background="#null"
android:text="[Block Status]"
android:id="#+id/btnStatus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="#id/txtBlock"
android:layout_toLeftOf="#+id/imgAlarm"
android:layout_alignParentLeft="true" />
Just added android:layout_below="#id/txtBlock" to your xml
Try Linear layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/txtBlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[Block Name]"
android:textSize="15sp"
android:layout_gravity="center" />
<Button
android:gravity="left|bottom"
android:background="#null"
android:text="[Block Status]"
android:id="#+id/btnStatus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/imgAlarm"
android:layout_alignParentLeft="true" />
</LinearLayout>
<ImageButton
android:id="#id/imgAlarm"
android:background="#null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/alarm"
android:layout_centerVertical="true"
android:layout_alignParentRight="true" />
</LinearLayout>

Categories

Resources