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
Related
I have button like this in my login activity layout.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:weightSum="2">
<com.google.android.material.button.MaterialButton
android:id="#+id/button_login_activity"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="1"
android:text="Login"
app:cornerRadius="20dp"
android:background="#color/colorPrimaryDark"
android:textColor="#color/toolbar_text"
android:textStyle="bold" />
<com.google.android.material.button.MaterialButton
android:id="#+id/button_skip_login_activity"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_marginStart="10dp"
android:layout_weight="1"
app:cornerRadius="20dp"
android:background="#color/colorPrimaryDark"
android:textColor="#color/toolbar_text"
android:text="Skip"
android:textStyle="bold"
android:layout_marginLeft="10dp" />
</LinearLayout>
My Style is like this
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!--Common Color-->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:alertDialogTheme">#style/AlertDialogTheme</item>
<item name="windowActionBar">true</item>
<item name="windowNoTitle">true</item>
<item name="colorSwitchThumbNormal">#color/switch_normal</item>
<item name="colorControlNormal">#color/switch_normal</item>
<item name="android:textColorSecondary">#color/switch_normal</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="android:windowDisablePreview">true</item>
</style>
I have dependency like below
implementation 'com.google.android.material:material:1.2.1'
I have tried many things but unable to make it working for round corner, same thing is working for my another project. Let me know if anyone can help me for come out from the issue.
Thanks!
You have to remove the background:
android:background="#color/colorPrimaryDark"
Using it the MaterialButton doesn't use its own MaterialShapeDrawable for the background. This means that features like shape appearance, stroke and rounded corners are ignored.
In your case use the app:backgroundTint attribute:
<com.google.android.material.button.MaterialButton
app:backgroundTint="#color/colorPrimaryDark"
I have applied a theme to my app but when I use textColor properties it override all other properties like textColorPrimary.
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowBackground">#color/windowBackground</item>
<item name="android:textColorPrimary">#FF4081</item>
<item name="android:textColorSecondary">#186925</item>
<item name="colorControlActivated">#FF0000</item> <!-- for check box when checked -->
<item name="colorControlNormal">#bbc40c</item> <!-- for check box when normal -->
<item name="colorButtonNormal">#325289</item>
<!--<item name="android:textColor">#084fe9</item>-->
<item name="android:windowAnimationStyle">#style/WindowAnimationTransition</item>
<!--<item name="android:windowActivityTransitions">true</item>
<item name="android:windowEnterTransition">#android:transition/slide_right</item>
<item name="android:windowExitTransition">#android:transition/slide_left</item>-->
</style>
<style name="AppTheme.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
<style name="HeaderText" parent="#android:style/TextAppearance.Large">
<item name="android:textColor">#ffffffff</item>
<item name="android:textSize">12dp</item>
</style>
<style name="WindowAnimationTransition">
<item name="android:windowEnterAnimation">#android:anim/fade_in</item>
<item name="android:windowExitAnimation">#android:anim/fade_out</item>
</style>
my Layout file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/questionNumberTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/scoreTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="17dp"
android:layout_marginEnd="16dp"
android:text="Score : 20"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/iconIv"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toStartOf="#+id/scoreTv"
app:layout_constraintStart_toEndOf="#+id/questionNumberTv"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="#tools:sample/avatars[11]" />
<TextView
android:id="#+id/questionTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"
android:text="TextView"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/iconIv" />
<Button
android:id="#+id/fiftyfiftyBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/radioGroup2" />
<RadioGroup
android:id="#+id/radioGroup2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/questionTitle">
<RadioButton
android:id="#+id/option1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:id="#+id/option2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:id="#+id/option3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:id="#+id/option4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton" />
</RadioGroup>
<TextView
android:id="#+id/votesTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:drawableLeft="#drawable/ic_expand_less_green_24dp"
android:text="20"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fiftyfiftyBtn" />
<TextView
android:id="#+id/commentCountTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:drawableLeft="#drawable/ic_expand_less_green_24dp"
android:text="35"
android:textSize="16sp"
app:layout_constraintStart_toEndOf="#+id/votesTv"
app:layout_constraintTop_toBottomOf="#+id/fiftyfiftyBtn" />
</android.support.constraint.ConstraintLayout>
when I Uncomment android:textColor , android:textColorPrimary color is override by android:textColor. I want my title/large text to use textColorPrimary and for medium and small I wanna use textColorPrimaryDark as said in their documentation.
before that the button text color is set by the textColorPrimary.
How could I use two text Color scheme for whole my app. using textColorPrimary and textColorPrimaryDark.
Or I have to create two textStyle and set them to each View. Is there a better approach to achieve what I want.
You need to define two styles and set your desired attributes there. It is cleaner to read and understandable. And also good behaviour to set your own style in textview.
Here is a sample you should do:
<style name="textStyle1" parent="android:TextAppearance">
<item name="android:textColor">#color/textColorPrimary</item>
<item name="android:textStyle">bold</item>
<item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
<item name="android:gravity">start</item>
<item name="android:textSize">22sp</item>
</style>
<style name="textStyle2" parent="android:TextAppearance">
<item name="android:textColor">#color/textColorPrimaryDark</item>
<item name="android:textStyle">normal</item>
<item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
<item name="android:gravity">start</item>
<item name="android:textSize">18sp</item>
</style>
Then use this style on your expected textview like this:
<TextView
android:id="#+id/tv_name"
style="#style/textStyleMedium"
........ />
Remove the below tags on your app theme:
<item name="android:textColorPrimary">#FF4081</item>
<item name="android:textColorSecondary">#186925</item>
<!-- <item name="android:textColor">#084fe9</item> -->
Purpose of different color:
TextColor is just the xml attribute to set a color to the text of any given view.
TextColorPrimary is the default text color for enabled buttons and Large Textviews.
TextColorSecondary is the default text color for Medium and Small Textviews.
colorPrimaryDark is the color of the status bar.
In order to achieve this you should remove textColor that override other colors.
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
inside your textView in xml . Then it will apply it to all your View. In this manner you don't have to set style to all ..
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" />
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
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