I am having troulbe fixing the following issue. I have a button with text OK. The button is nested inside a LinearLayout. This layout is nested inside two RelativeLayout. The second/inner RelativeLayout has `android:layout_margin="15dp". This is causing the text inside the button to be only half visible.
The XML is below. I am using it because it gives me the "popup" dialog with the (X) button on the top right corner.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<RelativeLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:padding="2dp"
android:background="#drawable/xml_round_corners_background"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp"
android:background="#drawable/xml_round_corners_background"
android:gravity="center_vertical|center_horizontal"
android:layout_weight="1"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
>
<TextView
android:id="#+id/exitTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:textAlignment="center"
android:text="TEXT....\n\n\n"
android:textColor="#color/white"
/>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:id="#+id/bluetooth_error_button_linearlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_below="#+id/exitTV"
>
<Button
android:layout_margin="15dp"
android:id="#+id/bt_error_message_ok_button"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/xml_botton1"
android:text="OK"
android:textColor="#color/DarkMagenta" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<Button
android:id="#+id/bt_error_message_x_button"
android:layout_alignParentRight="true"
android:text="X"
android:textColor="#FFF"
android:background="#drawable/xml_round_dismiss_button"
android:gravity="center_vertical|center_horizontal"
android:layout_margin="7sp"
android:layout_height="30sp"
android:layout_width="30sp"
android:textSize="15sp"
android:textStyle="bold"
android:onClick="cancelActivity" />
</RelativeLayout>
Could anyone please tell me what can i do to make the text fully visible?
I have changed/addded/removed attributes to the LinearLayout and the RelativeLayout the TextView, and the Button as well. but I could not make it work.
Thanks
EDIT:
This photo is how Eclipse shows the window, and its actually how I want it to be.
This is a partial screen shot from my phone. Samsumg Galaxy S III mini (4.0" screen)
I jsut realized that I was using another XML file as the background for each button. This XML was causing those issues.
rather than try to "text" with "background" in your XML, try using drawableTop (or ~Left ~Right or ~Bottom). These set the text so that the drawable is above "drawableTop" your text or where ever you want it
Related
I have a button help with a margin right and left of 10dp. Then I add a button test to the left of a TextView (centered horizontal), below the button help and align left to the button help.
The problem is that the button test is not exactly aligned to the button help like TextView test1 to the right of button help.
What am I doing wrong?
Here is my layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
>
<TextView
android:id="#+id/mid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="1"
android:gravity="center"
/>
<Button
android:id="#+id/help"
android:text="Help"
android:layout_width="match_parent"
android:layout_marginTop="35dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/help"
android:layout_marginTop="5dp"
android:background="#87CEFF"
android:text="Test"
android:layout_toLeftOf="#id/mid"
android:layout_alignLeft="#id/help"
/>
<TextView
android:id="#+id/test1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/mid"
android:layout_alignBottom="#id/test"
android:layout_alignTop="#id/test"
android:layout_alignRight="#id/help"
android:text="test1\ntest2"
android:gravity="center"
android:textColor="#0000ff"
android:background="#00cc00"
/>
</RelativeLayout>
i think thats just the background of the help-button.
if you use a custom background for it aswell, it will fill up all his space.
wrap test button and textview in a relative layout and align parent right and left each one.
There is nothing wrong in your code only one thing you have to add to your button test is android:background="#android:color/darker_gray" or any colour of your choice, android by default provides padding padding to button.
<Button
android:id="#+id/help"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="35dp"
android:background="#android:color/darker_gray"
android:text="Help" />
i have made necessary changes in above code try it hope it solves your issue
I am trying to get the following look (screenshot from my iOS app) on the Android version of my app.
I have defined my layout file as follows in Android:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="#+id/postTextTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/shareLILayout"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:ems="10"
android:gravity="top|left|start"
android:inputType="textMultiLine" >
<requestFocus />
</EditText>
<LinearLayout
android:id="#+id/shareLILayout"
android:layout_alignParentBottom="true"
android:background="#999999"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal" >
<ImageButton
android:contentDescription="#string/li_btn_desc"
android:id="#+id/postToLIButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:background="#android:color/transparent"
android:src="#drawable/linkedin_switch_off" />
<TextView
android:id="#+id/postToLITextView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/share_on_linkedin"
android:layout_gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
If I swap my ImageButton and TextView above, my app just crashed with a RuntimeException! Also I am not able to center the text so that its aligned to the center of the button. What am I doing wrong?
Simply swap the ImageButton and TextView order. Your runtime error is either unrelated or is caused by the need to clean your project before you need to redeploy it (sometimes resource IDs get funky). Also use android:gravity="center_vertical" for you TextView to center it properly
I need help with my layout.xml file size. I am probably missing something basic. I have created a search-function with a EditText, SearchButton and a ListView where I will display the search results.
Everytime you click on the EditText I need to make sure the background picture does'nt get resized when the softkeyboard is displayed, therefor my whole layout is placed in a ScrollView. That's basicly the only reason why I am using a ScrollView. But the ScrollView creates another problem aswell, look at the picture below:
http://tinypic.com/view.php?pic=6p3yix&s=6
For some reason my background picture refuses to fill the whole "background" area. Look at the bottom of the picture where it is black. So when I am testing on a phone with large screens it gets black at the bottom. How can I manage to fill the whole "background" area with my background-picture? Please help!
Edit: I have tested to use the layout.xml file without a ScrollView but have not made it work since without it, the the keyboard will change the size of the background picture. I have also tryed to use adjustPan in the android manifest file without any luck. Only solution that worked is with ScrollView, but now instead I get this problem with the background-pictures size... / Thanx!
My xml file:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/sorted_teams_scroll"
android:isScrollContainer="false">
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_search_task"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center|top"
android:orientation="vertical"
android:stretchColumns="1"
android:weightSum="1.0"
android:background="#drawable/orginalbild01"
>
<TableRow>
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.05">
</TextView>
<EditText
android:id="#+id/search_task_field"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.65"
android:hint="#string/SearchTaskHint" />
<Button
android:id="#+id/search_task_button"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="0.25"
android:text="#string/Search" />
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.05" >
</TextView>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="5dp" >
</TextView>
</TableRow>
<TableRow android:paddingLeft="40dp" >
<TextView
android:id="#+id/search_task_column_names"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#+id/search_task_column_names1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#+id/search_task_column_names2"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:textStyle="bold" >
</TextView>
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<ProgressBar
android:id="#+id/search_task_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateOnly="true"
android:visibility="gone" />
</TableRow>
<TableRow
android:paddingLeft="18dp"
android:paddingRight="18dp"
>
<ListView
android:id="#+id/search_task_list"
android:layout_width="fill_parent"
android:layout_height="355dp"
android:gravity="left" />
</TableRow>
</TableLayout>
</ScrollView>
If you have problem only with keyboard then...
just try this to disable the layout resize when keyboard is popped up -
In your manifest file add this to your activity...
android:windowSoftInputMode="adjustPan"
Pls post complete code... in above code you set background for table layout.. how it will apply for full background.. post your code without scrollview...
I have a problem with centering text on buttons in a layout that I am working on. Please see the screenshot below (taken within eclipse's "Graphical Layout" tab):
I'm not sure what's causing this. I tried playing around with the individual layout properties of the buttons, but this has not had any effect. The following is my layout hierarchy:
LinearLayout (orientation is "vertical")
...
RelativeLayout
Button ("MM/DD/YYYY")
Button ("HH:MM")
TextView ("to")
Button ("MM/DD/YYYY")
Button ("HH:MM")
...
LinearLayout (orientation is "horizontal")
Button ("Close"; layout_weight is "1")
Button ("Reserve Room"; layout_weight is "1")
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="1024dp"
android:layout_height="640dp"
android:orientation="vertical"
android:padding="10dp" >
...
<RelativeLayout
android:id="#+id/dateTimePickersLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/startingDateButton"
android:layout_width="244dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="#string/mm_dd_yyyy" />
<Button
android:id="#+id/endingTimeButton"
android:layout_width="244dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="#string/hh_mm" />
<Button
android:id="#+id/endingDateButton"
android:layout_width="244dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/endingTimeButton"
android:text="#string/mm_dd_yyyy" />
<Button
android:id="#+id/startingTimeButton"
android:layout_width="244dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/startingDateButton"
android:text="#string/hh_mm" />
<TextView
android:id="#+id/toTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:text="#string/to"
android:textSize="18dp" />
</RelativeLayout>
...
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/closeButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/close" />
<Button
android:id="#+id/reserveRoomButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/reserve_room" />
</LinearLayout>
</LinearLayout>
Anyone have any ideas what may be causing this?
Thank you for your help!
I ended up updating eclipse and that fixed the problem. I was extremely disappointed that restarting the IDE did not change anything, especially since the XML had not posed any problems for others. Thanks for the help, everyone!
Make sure the width of your buttons at the bottom is set to 0dp. Also make sure that their parent LinearLayout has a width set to match_parent.
I am new to android, currently designing a User Home Page. please let me know how to align UI controls like - Button , EditText, etc to left/right/center in Linear and List Layout. button code eg.
you can achieve this by using set gravity of layout . here i have one xml file in which i have two image button and one text view . Here i set text view in center . So its fits to all devices.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton
android:id="#+id/Back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/back"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"/>
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold"
android:singleLine="true"
android:text="Top 100"/>
</LinearLayout>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:id="#+id/Playing"
android:visibility="invisible"
android:src="#drawable/nowplaying"
android:layout_gravity="center_vertical"
android:paddingTop="3dp"/>
</LinearLayout>
</LinearLayout>
Checkout the android:layout* properties and the android:gravity properties and this example.