Below is the XML I am using and when I use the android:textStyle="italic" attribute, the text doesn't show up. Basically any TextView with the style SummarySubtitle will not show up.
<style name="SummarySubtitle" parent="#android:style/TextAppearance">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:gravity">right|center_vertical</item>
<item name="android:layout_weight">1</item>
<item name="android:paddingRight">6dp</item>
<item name="android:textSize">12dp</item>
<item name="android:textStyle">italic</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="70dp"
android:orientation="vertical">
<LinearLayout android:id="#+id/summary_header"
android:layout_width="fill_parent" android:layout_height="30dp"
android:orientation="horizontal">
<TextView android:id="#+id/summary_title" android:text="Title"
style="#style/SummaryTitle"/>
<TextView android:id="#+id/summary_subtitle"
android:text="Subtitle " style="#style/SummarySubtitle"/>
</LinearLayout>
<LinearLayout android:id="#+id/summary_subheader"
android:layout_width="fill_parent" android:layout_height="20dp"
android:orientation="horizontal">
<TextView android:id="#+id/summary_min" android:text="#string/min"
style="#style/SummaryHeader"/>
<TextView android:id="#+id/summary_max" android:text="#string/max"
style="#style/SummaryHeader"/>
<TextView android:id="#+id/summary_avg" android:text="#string/avg"
style="#style/SummaryHeader"/>
</LinearLayout>
<LinearLayout android:id="#+id/summary_values"
android:layout_width="fill_parent" android:layout_height="20dp"
android:orientation="horizontal">
<TextView android:id="#+id/summary_value_min"
android:text="$0.00" style="#style/SummaryValue"/>
<TextView android:id="#+id/summary_value_max"
android:text="$0.00" style="#style/SummaryValue"/>
<TextView android:id="#+id/summary_value_avg"
android:text="$0.00" style="#style/SummaryValue"/>
</LinearLayout>
</LinearLayout>
All I found on the subject so far
http://groups.google.com/group/android-developers/browse_thread/thread/843376e298e95e14
Relevant quote: "Oh yeah, I have seen that too. But when you run your app, it renders
correctly."
It doesn't show up on the layout's graphical representation but works correctly when you build and run the app.
try using this code:
adInfoTV.setTypeface(Typeface.MONOSPACE,Typeface.ITALIC);
Related
In my Activity_main.xml file I have added few lines of code for a horizontal line but when I run the emulator it does not show up.
<TextView
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="center"
android:layout_weight="1"
android:divider="?android:dividerHorizontal"
android:gravity="center"
android:orientation="vertical"
android:textAppearance="#style/Divider"
android:showDividers="middle"/>
Styles.xml
<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>
It does not show any errors? Any suggestions?
Using your approach,
Replace
<TextView
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="center"
android:layout_weight="1"
android:divider="?android:dividerHorizontal"
android:gravity="center"
android:orientation="vertical"
android:textAppearance="#style/Divider"
android:showDividers="middle"/>
With
<TextView
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="center"
android:gravity="center"
android:background="#color/colorPrimary"/>
You don't really need to use a TextView. You can simply use a View
In your layout file:
<View style="#style/HRLine">
In your style file:
<style name="HRLine">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
<item name="android:background">#color/yourLineColor</item>
</style>
I have created a button layout with 4 separate "border" views (left, right, top, bottom) and alpha-numeric text intended to be in the center. I using the 4 separate border views so I can selectively hide (or not) each side. When used in a grid layout, I intend to enable the borders on a per button basis to create gridlines between the buttons (think tic-tac-toe lines).
But I cannot seem to center the alpha-numeric text vertically inside the button. Any help would be appreciated.
Here is the relevant xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/dialPadButton"
android:id="#+id/pad_btn_2"
android:orientation="horizontal"
android:background="#android:color/darker_gray">
<!-- Left Border -->
<View style="#style/dialPadButtonVerticalBorderStyle"
android:id="#+id/left_border"
android:visibility="visible"
android:layout_alignParentLeft="true"
></View>
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Top Border -->
<View style="#style/dialPadButtonHorizontalBorderStyle"
android:id="#+id/top_border"
android:visibility="visible"
android:layout_alignParentTop="true"
></View>
<!-- Alpha-numeric text -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="vertical">
<TextView style="#style/dialPadButtonNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="#dimen/dial_number_text_size"
android:text="2"
android:layout_gravity="center" />
<TextView style="#style/dialPadButtonText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/dial_letter_text_size"
android:text="abc"
android:layout_gravity="center" />
</LinearLayout>
<!-- Bottom Border -->
<View style="#style/dialPadButtonHorizontalBorderStyle"
android:id="#+id/bottom_border"
android:visibility="visible"
android:layout_alignParentBottom="true"
></View>
</RelativeLayout>
<!-- Right Border -->
<View style="#style/dialPadButtonVerticalBorderStyle"
android:id="#+id/right_border"
android:visibility="visible"
android:layout_alignParentRight="true"
></View>
</RelativeLayout>
For additional reference, here are the style definitions:
<resources>
<style name="dialPadButton">
<item name="android:layout_width">100dp</item>
<item name="android:layout_height">100dp</item>
<item name="android:fontFamily">sans-serif</item>
</style>
<style name="dialPadButtonNumber">
<item name="android:textColor">#00FF00</item>
<item name="android:maxLines">1</item>
</style>
<style name="dialPadButtonText">
<item name="android:textColor">#00FF00</item>
<item name="android:layout_marginTop">-10dp</item>
<item name="android:maxLines">1</item>
</style>
<style name="dialPadButtonHorizontalBorderStyle">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">2dp</item>
<item name="android:background">#EEEEEE</item>
</style>
<style name="dialPadButtonVerticalBorderStyle">
<item name="android:layout_height">match_parent</item>
<item name="android:layout_width">2dp</item>
<item name="android:background">#EEEEEE</item>
</style>
</resources>
you can do these
android:gravity="center"
or
android:layout_height="wrap_content"
on your LinearLayout
simply add
android:gravity="center"
to the linearlayout that holds the two textviews, the linear layout is defined match parent so you need the children to be gravity:center
like this :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical">
<TextView style="#style/dialPadButtonNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="25sp"
android:text="2"
android:layout_gravity="center" />
<TextView style="#style/dialPadButtonText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="abc"
android:layout_gravity="center" />
</LinearLayout>
Not too sure how to word this but if you look at my picture below the blue of Victoria disappears off the screen but i'd like to to start a new line so you can clearly see the whole thing.
Heres my xml for for each list component. I have 5 textviews which are situated to the right of the preceding one, how can I pickup when one is too long for the line and move to another line?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/tube_stop_graphic1"
android:orientation="horizontal"
android:gravity="center_vertical|center_horizontal"
android:layout_width="25sp"
android:layout_height="25sp"
android:scaleType="fitXY"/>
<ImageView
android:id="#+id/tube_stop_graphic2"
android:orientation="horizontal"
android:gravity="center_vertical|center_horizontal"
android:layout_width="25sp"
android:layout_height="25sp"
android:scaleType="fitXY"
android:layout_below="#id/tube_stop_graphic1"/>
<ImageView
android:id="#+id/tube_stop_graphic3"
android:orientation="horizontal"
android:gravity="center_vertical|center_horizontal"
android:layout_width="25sp"
android:layout_height="25sp"
android:scaleType="fitXY"
android:layout_below="#id/tube_stop_graphic2"/>
<TextView
android:id="#+id/tube_stop_name"
android:orientation="horizontal"
android:paddingLeft="10px"
android:textSize="20sp"
android:text="BLABLA"
android:textStyle="normal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/tube_stop_graphic1"/>
<TextView
android:id="#+id/tube_stop_distance"
android:orientation="horizontal"
android:layout_alignParentRight="true"
android:gravity="right|center"
android:paddingRight="10px"
android:text="BLABLA"
android:textSize="14sp"
android:textStyle="normal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="#id/tube_stop_name"/>
<TextView
android:id="#+id/tube_line1"
style="#style/Tube_Stop_TextView"
android:text="Overgound"
android:layout_toRightOf="#id/tube_stop_graphic1"
android:layout_below="#id/tube_stop_name"/>
<TextView
android:id="#+id/tube_line2"
style="#style/Tube_Stop_TextView"
android:layout_toRightOf="#id/tube_line1"
android:layout_below="#id/tube_stop_name"/>
<TextView
android:id="#+id/tube_line3"
style="#style/Tube_Stop_TextView"
android:layout_toRightOf="#id/tube_line2"
android:layout_below="#id/tube_stop_name"/>
<TextView
android:id="#+id/tube_line4"
style="#style/Tube_Stop_TextView"
android:layout_toRightOf="#id/tube_line3"
android:layout_below="#id/tube_stop_name"/>
<TextView
android:id="#+id/tube_line5"
style="#style/Tube_Stop_TextView"
android:layout_toRightOf="#id/tube_line4"
android:layout_below="#id/tube_stop_name"/>
</RelativeLayout>
and the style for each of them
<style name="Tube_Stop_TextView">
<item name="android:gravity">center_vertical|center_horizontal</item>
<item name="android:paddingLeft">5sp</item>
<item name="android:paddingTop">5sp</item>
<item name="android:paddingBottom">5sp</item>
<item name="android:paddingRight">5sp</item>
<item name="android:textSize">10sp</item>
<item name="android:textStyle">normal</item>
<item name="android:background">#drawable/rounded_square</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:inputType">text</item>
</style>
It will be better if you wrap all your textviews in a gridview. Because your first TextView is having long text here. Gridview will push any view which is out of available width to a new row.
i want to create header in android with text and buttons like in iOS (Text in Cetner and Buttons on right and left side), i have tried but not useful at all,please guide me ... how can i make this one for my app
Try this. Make header.xml file and put below code in it and use it in any layout file using include .
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/titlebar"
android:gravity="center">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/back_button"
android:background="#android:color/transparent"
android:layout_marginLeft="5.0dip"
android:id="#+id/imageButtonBack"
android:contentDescription="#string/ui_image_home_description"/>
<TextView
android:id="#+id/textViewTitleBar"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
style="#style/TitleBarText"
android:singleLine="false"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/home_button"
android:background="#android:color/transparent"
android:layout_marginRight="5.0dip"
android:id="#+id/imageButtonHome"
android:contentDescription="#string/ui_image_home_description"/>
</LinearLayout>
Note : Add the below style to style.xml in res/values folder.
<style name="TitleBarText">
<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"> 17sp </item>
<item name="android:paddingLeft">12dip</item>
<item name="android:paddingRight">12dip</item>
<item name="android:textColor">#color/white</item>
<item name="android:singleLine">true</item>
<item name="android:ellipsize">end</item>
</style>
This is an easier one. You can try this:
<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" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/header">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Back" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Next" />
</RelativeLayout>
</RelativeLayout>
In Tim Bray's latest Android blog post he mentions the "dashboard" ui pattern (what is used for the Twitter app, Facebook app, etc. Is this layout as simple as a GridView with Buttons or is it something else?
Update:
The DashboardLayout was released by Roman Nurik last night. It is a derivative of the layout used in the Google IO 2010 app.
The best example you can use is from the Google I/O 2011 Android App. They implement all those design patterns in their app. You can find the code at the following link:
http://code.google.com/p/iosched/source/browse/android/res/layout/fragment_dashboard.xml?r=27a82ff10b436da5914a3961df245ff8f66b6252
The 2011 version uses a custom layout called 'DashboardLayout' in a fragment which gets shared in phone and tablet specific layouts. The logic in DashboardLayout is responsible for all the auto layout magic!
Code of DashboardLayout from IO 2010 app was rather buggy. But Roman Nurik has fixed it and now it's possible to use DashboardLayout easily in your app.
Howto:
Add this class into your project
In your layout, just drop couple of buttons inside DashboardLayout, similar like here.
I was able to achieve a similar dashboard using a relative layout. Its still a work in progress, so your mileage may vary.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/lay_wrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout android:id="#+id/lay_action"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000" >
<TextView android:id="#+id/label_header"
android:layout_width="wrap_content"
android:layout_height="50px"
android:text="#string/app_title"
android:textColor="#000000"
android:textSize="25sp"
android:paddingLeft="10px"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
/>
</LinearLayout>
<RelativeLayout android:id="#+id/lay_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/lay_action"
android:paddingTop="25px"
android:layout_centerInParent="true">
<Button android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button1"
android:padding="25dip"
android:drawableTop="#drawable/button1" />
<Button android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/button1"
android:text="#string/button2"
android:padding="25dip"
android:drawableTop="#drawable/button2" />
<Button android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/button1"
android:text="#string/button3"
android:padding="25dip"
android:drawableTop="#drawable/button3" />
<Button android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/button3"
android:layout_below="#id/button2"
android:text="#string/button4"
android:padding="25dip"
android:drawableTop="#drawable/button4" />
</RelativeLayout>
</RelativeLayout>
The Dashboard layout did not work for me, thus I suggest a layout based solution.
It's just a bunch of layouts within layouts.
The key is the relativity of weights between the spacing layouts and the content layouts.
You can very simply move icons and define other layouts for bigger or lighter dashboards.
Here is how it looks like:
And here is the xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/dashboard"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout style="#style/dashboard_space_vertical" />
<LinearLayout style="#style/dashboard_content_vertical" >
<FrameLayout style="#style/dashboard_space_horizontal" >
</FrameLayout>
<LinearLayout style="#style/dashboard_content_horizontal" >
<ImageView
style="#style/dashboard_imageview"
android:src="#android:drawable/sym_call_missed" />
<TextView
style="#style/dashboard_textview"
android:text="Text 1" />
</LinearLayout>
<FrameLayout style="#style/dashboard_space_horizontal" />
<LinearLayout style="#style/dashboard_content_horizontal" >
<ImageView
style="#style/dashboard_imageview"
android:src="#android:drawable/sym_call_missed" />
<TextView
style="#style/dashboard_textview"
android:text="Text 2" />
</LinearLayout>
<FrameLayout style="#style/dashboard_space_horizontal" />
</LinearLayout>
<FrameLayout style="#style/dashboard_space_vertical" />
<LinearLayout style="#style/dashboard_content_vertical" >
<FrameLayout style="#style/dashboard_space_horizontal" />
<LinearLayout style="#style/dashboard_content_horizontal" >
<ImageView
style="#style/dashboard_imageview"
android:src="#android:drawable/sym_call_missed" />
<TextView
style="#style/dashboard_textview"
android:text="Text 3" />
</LinearLayout>
<FrameLayout style="#style/dashboard_space_horizontal" />
<LinearLayout style="#style/dashboard_content_horizontal" >
<ImageView
style="#style/dashboard_imageview"
android:src="#android:drawable/sym_call_missed" />
<TextView
style="#style/dashboard_textview"
android:text="Text 4" />
</LinearLayout>
<FrameLayout style="#style/dashboard_space_horizontal" />
</LinearLayout>
<FrameLayout style="#style/dashboard_space_vertical" />
<LinearLayout style="#style/dashboard_content_vertical" >
<FrameLayout style="#style/dashboard_space_horizontal" />
<LinearLayout style="#style/dashboard_content_horizontal" >
<ImageView
style="#style/dashboard_imageview"
android:src="#android:drawable/sym_call_missed" />
<TextView
style="#style/dashboard_textview"
android:text="Text 5" />
</LinearLayout>
<FrameLayout style="#style/dashboard_space_horizontal" />
<LinearLayout style="#style/dashboard_content_horizontal" >
<ImageView
style="#style/dashboard_imageview"
android:src="#android:drawable/sym_call_missed" />
<TextView
style="#style/dashboard_textview"
android:text="Text 6" />
</LinearLayout>
<FrameLayout style="#style/dashboard_space_horizontal" />
</LinearLayout>
<FrameLayout style="#style/dashboard_space_vertical" />
</LinearLayout>
Here are the styles:
<resources>
<style name="dashboard_space_vertical">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">0px</item>
<item name="android:layout_weight">1</item>
</style>
<style name="dashboard_content_vertical">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">0px</item>
<item name="android:layout_weight">3</item>
<item name="android:layout_gravity">center</item>
</style>
<style name="dashboard_space_horizontal">
<item name="android:layout_width">0px</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">2</item>
<!-- <item name="android:background">#color/black</item> -->
</style>
<style name="dashboard_content_horizontal">
<item name="android:layout_width">0px</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">3</item>
<item name="android:orientation">vertical</item>
<item name="android:layout_gravity">center</item>
<item name="android:gravity">center</item>
</style>
<style name="dashboard_imageview">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:scaleType">fitCenter</item>
</style>
<style name="dashboard_textview">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:gravity">center</item>
<item name="android:textSize">#dimen/dashboard_thumbnail_text_size</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/blue</item>
</style>
</resources>
Hope this helps someone. Enjoy.
It could be implemented with a TableLayout containing Image- and TextViews.
the best and the simplest way of creating Dashboard..
very nicely explained
How To Build A Dashboard User Interface In Android
romannurik posted recently a custom ViewGroup to do this. The code is here.