I have created a simple table with varies length of text. I'm using layout_height=wrap_content in my table row. If you see the picture, it has a wide spaces between the next element and the previous one. If I set the height, then the spaces will remained when viewed in landscape. I don't know where to fixed it. I mostly used styles... so it's weird that some are working and some not.
sampleLayout.xml
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="90dp"
android:background="#color/form_background"
android:shrinkColumns="*"
android:stretchColumns="*">
<!--Table header-->
<TableRow
style="#style/table_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/th_component"
style="#style/table_header"
android:layout_height="match_parent"
android:layout_weight="2.8"
android:text="#string/tableH_komponen"/>
<TextView
android:id="#+id/th_marks"
style="#style/table_header"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/tableH_markah"/>
<TextView
android:id="#+id/th_demerits"
style="#style/table_header"
android:layout_height="match_parent"
android:layout_weight="0.7"
android:text="#string/tableH_demerit"/>
<TextView
android:id="#+id/th_notes"
style="#style/table_header"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:text="#string/tableH_catatan"/>
</TableRow>
<!--Component C1-->
<TableRow
style="#style/table_row"
android:layout_height="wrap_content">
<TextView
style="#style/table_attr"
android:text="#string/c1"/>
<TextView
android:id="#+id/tv_cC1"
style="#style/table_component"
android:text="#string/cC1"
/>
<TextView
android:id="#+id/tv_mc1"
style="#style/table_marks"
android:layout_height="wrap_content"
android:text="#string/_6"/>
<CheckBox
android:id="#+id/checkBox_c1"
style="#style/table_demerit"
android:layout_height="wrap_content"/>
<ImageButton
android:id="#+id/btn_c1"
style="#style/table_notes"
android:layout_height="wrap_content"
android:text="#string/catatan"/>
</TableRow>
<!--Component C2-->
<TableRow
style="#style/table_row"
android:layout_height="wrap_content">
<TextView
style="#style/table_attr"
android:text="#string/c2"/>
<TextView
android:id="#+id/tv_cC2"
style="#style/table_headComponent"
android:text="#string/cC2"/>
<ImageButton
android:id="#+id/btn_c2"
style="#style/table_notes"
android:layout_height="wrap_content"
android:text="#string/catatan"/>
</TableRow>
<TableRow
style="#style/table_row"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_cC2_1"
style="#style/table_subComponent"
android:text="#string/cC2_1"/>
<TextView
android:id="#+id/tv_mC2_1"
style="#style/table_marks"
android:layout_height="match_parent"
android:text="#string/_1"/>
<CheckBox
android:id="#+id/checkBox_c2_1"
style="#style/table_subDemerit"
android:layout_height="wrap_content"/>
</TableRow>
<TableRow
style="#style/table_row"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_cC2_2"
style="#style/table_subComponent"
android:layout_height="wrap_content"
android:text="#string/cC2_2"/>
<TextView
android:id="#+id/tv_mC2_2"
style="#style/table_marks"
android:layout_height="wrap_content"
android:text="#string/_1"/>
<CheckBox
android:id="#+id/checkBox_c2_2"
style="#style/table_subDemerit"
android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
</FrameLayout>
strings.xml
<resources>
<!--Case C-->
<string name="cC1">Pemeriksaan kesihatan ke atas semua pengendali makanan:
\n - Mendapat suntikan pelalian anti-tifoid
\n - Menghadiri Latihan Pengendali Makanan </string>
<string name="cC2">Tahap kebersihan diri yang baik:</string>
<string name="cC2_1">- Berpakaian bersih dan bersesuaian</string>
<string name="cC2_2">- Memakai apron yang bersih dan berpenutup kepala</string>
</resources>
styles.xml
<resources>
<!--kpkt table header-->
<style name="table_header">
<item name="android:textSize">#dimen/textSize_subheading</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/table_textcolor</item>
<item name="android:background">#color/table_background</item>
<item name="android:padding">#dimen/text_padding</item>
<item name="android:layout_width">0dp</item>
<item name="android:gravity">center</item>
</style>
<!--table style-->
<style name="table_row">
<item name="android:gravity">end</item>
<item name="android:layout_width">0dp</item>
<item name="android:weightSum">5</item>
</style>
<style name="table_attr">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">0.3</item>
<item name="android:gravity">center</item>
</style>
<style name="table_component">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">2.5</item>
<item name="android:paddingTop">8dp</item>
<item name="android:paddingBottom">8dp</item>
</style>
<style name="table_marks">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">center</item>
<item name="android:padding">8dp</item>
</style>
<style name="table_demerit">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">0.7</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:visibility">visible</item>
</style>
<style name="table_notes">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">0.5</item>
<item name="srcCompat">#drawable/ic_edit</item>
<item name="android:contentDescription">catatan</item>
<!--<item name="android:drawableBottom">#drawable/ic_edit</item>-->
<!--<item name="android:drawableTop">#drawable/ic_edit</item>-->
</style>
<!--kpkt table head component-->
<style name="table_headComponent">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">40dp</item>
<item name="android:padding">#dimen/text_padding</item>
<item name="android:layout_weight">4.2</item>
</style>
<!--kpkt table subcomponent-->
<style name="table_subDemerit">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1.2</item>
<item name="android:visibility">visible</item>
</style>
<style name="table_subComponent">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">40dp</item>
<item name="android:padding">8dp</item>
<item name="android:layout_weight">2.5</item>
</style>
</resources>
I can suggest you to understand the concept of wrap_content and match_parent, to get better solution.
I think you can use linear layout with horizontal and vertical orientation.
Because linear layout is more flexible and gives you better performance than table layout and table row.
Q: When we should use table layout and table row?
Ans: when we have a similar type of data, and we want to represent in rows and columns view then we should use table layout and table row.
But if we have non linear data, then we should not use table layout and table row...and I think you have non linear data.
For better understanding of showing data in non linear form, you should know the weight_sum and layout_weight property of linear layouts.
Related
I was wondering how I can manage to align all columns in rows. I am using a ListView, where I display a list of drugs for my game. The columns are different sizes each row. I would like to see that each column has the same width all down to the end of the list, but not have same width overall.
As you can see from the picture, the columns are not aligned. I draw the lines to make it even more obvious what I would like. You can also see that the buttons are to close to the other column. With the arrow on the picture I wanted to make it clear that those buttons should be placed more to the end of the row.
My implementation uses the following styles:
<!-- List style for the drug sell list -->
<style name="traderY.List">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_alignParentLeft">true</item>
<item name="android:layout_alignParentTop">true</item>
</style>
<!-- Header style for quantity column -->
<style name="traderY.HeaderQuantityText">
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">0.15</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">15dip</item>
<item name="android:padding">4dip</item>
<item name="android:layout_margin">4dip</item>
<item name="android:textColor">#EDEFF0</item>
</style>
<!-- Header style for cost column -->
<style name="traderY.HeaderCostText">
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">0.20</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">15dip</item>
<item name="android:padding">4dip</item>
<item name="android:layout_margin">4dip</item>
<item name="android:textColor">#EDEFF0</item>
</style>
<!-- Header style for name column -->
<style name="traderY.HeaderNameText">
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">0.45</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">15dip</item>
<item name="android:padding">4dip</item>
<item name="android:layout_margin">4dip</item>
<item name="android:textColor">#EDEFF0</item>
</style>
<!-- Row style for quantity column -->
<style name="traderY.QuantityListText">
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">0.15</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">15dip</item>
<item name="android:padding">4dip</item>
<item name="android:layout_margin">4dip</item>
<item name="android:textColor">#000000</item>
</style>
<!-- Row style for cost column -->
<style name="traderY.CostListText">
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">0.20</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">15dip</item>
<item name="android:padding">4dip</item>
<item name="android:layout_margin">4dip</item>
<item name="android:textColor">#000000</item>
</style>
<!-- Row style for name column -->
<style name="traderY.NameListText">
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">0.45</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">15dip</item>
<item name="android:padding">4dip</item>
<item name="android:layout_margin">4dip</item>
<item name="android:textColor">#000000</item>
</style>
<!-- Row style for button column -->
<style name="traderY.ListButton" parent="#android:style/Widget.Button">
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">0.20</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">15dip</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:gravity">center</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">0.6</item>
<item name="android:background">#drawable/custom_btn_black_pearl</item>
<item name="android:padding">4dip</item>
</style>
As you can see I set or I try to set the column width by using those two items:
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">0.20</item>
I was reading that you can set the width by using weight. I basically used the same values I would use to set percentages. If I understand correctly, the weight value represents the ratio between other components. I found this as a solution on a Stack Overflow question and I found it in several tutorials. One of the tutorials I found is this one here.
To share more light, here are also the layouts of the of all the components, starting with the fragment which contains the list view.
Fragment layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/money"
style="#style/traderY.TextCenter" />
<TextView
android:id="#+id/location"
style="#style/traderY.TextCenter" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/junkie_icon"/>
<ListView
android:id="#+id/drug_list"
style="#style/traderY.List"
android:layout_weight="1"/>
<TableRow
style="#style/traderY.ButtonRow">
<Button
android:id="#+id/nothing"
style="#style/traderY.ButtonCenter"
android:text="#string/exit"/>
</TableRow>
</LinearLayout>
Here is the header layout. As you can see I omit the last column for buttons, because there is no need to display a header for it:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#000000">
<TextView
android:text="#string/header_quantity"
style="#style/traderY.HeaderQuantityText" />
<TextView
android:text="#string/header_cost"
style="#style/traderY.HeaderCostText" />
<TextView
android:text="#string/header_name"
style="#style/traderY.HeaderNameText" />
</LinearLayout>
And here is the layout for each row I use:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/drug_quantity"
style="#style/traderY.QuantityListText" />
<TextView
android:id="#+id/drug_cost"
style="#style/traderY.CostListText" />
<TextView
android:id="#+id/drug_name"
style="#style/traderY.NameListText" />
<Button
android:id="#+id/drug_sell_btn"
android:text="#string/sell_drugs_action"
style="#style/traderY.ListButton"/>
</LinearLayout>
Those are the style/layouts I use and I do not change any of those properties in the code. So the problem can only be in my XML files.
Does anyone know what am I doing wrong here? Maybe my investigation is wrong and I can not do it. I would appreciate any help or comments to solve this problem. If this is not even possible, then please let me know.
I found out that my solution was correct. The weight property did the job. For some unknown reason gradle did not see the changes when it was building the app. Or maybe it is the emulator. This was not the first time something like this happened. I will have to investigate why this even occur.
Increase weight of style="#style/traderY.QuantityListText". Make 0.2 or 0.3
Wrap your text views in a LinearLayout and set it to fill the parentView. In this way all the buttons will be aligned to the right.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/drug_quantity"
style="#style/traderY.QuantityListText" />
<TextView
android:id="#+id/drug_cost"
style="#style/traderY.CostListText" />
<TextView
android:id="#+id/drug_name"
style="#style/traderY.NameListText" />
</LinearLayout>
<Button
android:id="#+id/drug_sell_btn"
android:text="#string/sell_drugs_action"
style="#style/traderY.ListButton"/>
</LinearLayout>
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"
I have a simple table layout that looks like this:
http://imgur.com/beU9LbR
My problem is that whenever I type text into the Artist, Venue or Comments EditText boxes, once the text string is in line vertically with the start of the Date TextView, the TextView start position moves position to stay in line with the string of characters; like this:
http://imgur.com/7f7eal8
I'm not sure if the Button is trying to match its end point to the string of characters or if the TextView is trying to match its start point to the string of characters but either way somethings not right.
Can anyone give me some insight as to what is happening here?
Thanks in advance!
Here is the XML file for the page shown:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<TextView
style="#style/titleBar"
android:id="#+id/addTitle"
android:text="#string/add" />
<TableLayout
style="#style/my_table"
android:id="#+id/addTable"
android:layout_below="#+id/addTitle">
<TableRow>
<TextView
style="#style/largeText"
android:text="#string/artistName"/>
</TableRow>
<TableRow>
<EditText
style="#style/tableEditText"
android:id="#+id/editName"/>
</TableRow>
<TableRow>
<TextView
style="#style/largeText"
android:text="#string/venue"/>
</TableRow>
<TableRow>
<EditText
style="#style/tableEditText"
android:id="#+id/editVenue"/>
</TableRow>
<TableRow>
<TextView
style="#style/largeText"
android:text="#string/date"/>
</TableRow>
<TableRow>
<Button
android:background="#android:color/transparent"
android:drawableRight="#drawable/event_1"
android:id="#+id/setDateButton"/>
<TextView
style="#style/tableEditText"
android:layout_weight="3"
android:layout_width="200dp"
android:id="#+id/editDate"/>
</TableRow>
<TableRow>
<TextView
style="#style/largeText"
android:text="#string/comments"/>
</TableRow>
<TableRow>
<EditText
style="#style/tableEditText"
android:inputType="textNoSuggestions|textCapSentences|textMultiLine"
android:lines="3"
android:id="#+id/editComments"/>
</TableRow>
</TableLayout>
<Button
android:id="#+id/addButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="#drawable/add"
android:background="#android:color/transparent"
android:textColor="#color/grey"
android:padding="20dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Here is the styles.xml file:
<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.Holo.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="largeText">
<item name="android:textColor">#color/grey</item>
<item name="android:textSize">25sp</item>
<item name="android:padding">3dp</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">left</item>
<item name="android:layout_marginRight">20sp</item>
</style>
<style name="largeText2">
<item name="android:textSize">25sp</item>
<item name="android:padding">3dp</item>
<item name="android:background">#color/bgOrange</item>
<item name="android:textColor">#color/nearBlack</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">left</item>
<item name="android:layout_marginRight">20sp</item>
</style>
<style name="titleBar">
<item name="android:textColor">#fff</item>
<item name="android:textSize">25sp</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_alignParentTop">true</item>
<item name="android:layout_centerHorizontal">true</item>
<item name="android:gravity">left</item>
<item name="android:padding">20sp</item>
<item name="android:background">#color/headingOrange</item>
</style>
<style name="my_table">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:padding">15sp</item>
</style>
<style name="tableEditText">
<item name="android:inputType">textCapSentences|textNoSuggestions|textAutoComplete</item>
<item name="android:background">#color/bgOrange</item>
<item name="android:textColor">#color/nearBlack</item>
<item name="android:gravity">left</item>
<item name="android:padding">3dip</item>
<item name="android:textSize">25sp</item>
<item name="android:layout_weight">1</item>
</style>
<style name="smallIcon">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_gravity">left</item>
<item name="android:padding">2dp</item>
</style>
</resources>
This is happening because of your use of the TableLayout while not fully appreciating how it works. What it does is it goes through and figures out how many columns it will have. For each TableRow it will put the views in each column starting from the first defined view to the last.
What is happening is that your first TextView for artistName is in column 1. The next few TableRow only have 1 column. Then you get to the TableRow with setDateButton which creates two columns. Now all the other views previously assigned will be in column 1 with a column 2 after them which would be as wide as editDate if they had another view.
As a result setDateButton is now as wide as your artistName TextView and since you are using android:drawableRight the image is being placed to the right side of the Button.
You're going to need to adjust layout_column and layout_span values to adjust the layout. Alternatively, I would suggest removing the TableLayout and using the RelativeLayout appropriately.
Try wrapping the Button and TextView with a LinearLayout
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
I have a spinner, an edittext and a button in a horizontal linearlayout. When I have enter something into edittext, it increase every character and others decrease. There is an eanough blank area input but it does not change, every time it increase how long character I input.
How can I fix it?
layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/ly"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="10" >
<Spinner
android:id="#+id/spinner1"
style="#style/submitspinner"
android:layout_weight="2"
android:entries="#array/a_code"
android:prompt="#string/p_code" />
<EditText
android:id="#+id/editText1"
style="#style/submitstyle"
android:layout_weight="5"
android:inputType="number" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
style="#style/submitstyle"
android:layout_weight="3"
android:text="#string/btn_submit" />
</LinearLayout>
style
<style name="submitstyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_margin">10sp</item>
<item name="android:textColor">#android:color/holo_blue_dark</item>
<item name="android:textSize">#dimen/pt</item>
</style>
<style name="submitspinner" parent="#android:TextAppearance.Widget.TextView.SpinnerItem">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_margin">10sp</item>
<item name="android:textColor">#android:color/holo_blue_dark</item>
<item name="android:textSize">#dimen/pt</item>
</style>
I have changed style as below and it worked well...
submitstyle and submitspinner style
from
<item name="android:layout_width">wrap_content</item>
to
<item name="android:layout_width">0dp</item>
I found good tuts for this but I have closed the tab, I cannot share it...
//change you style from
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
//to
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>