Android - Thin transparent line running through spinners, device specific? - android

Mysterious transparent lines are showing up in our spinners on certain devices. I've seen this before but there must be a way to get rid of them... I'm assuming it's something janky with the 9-patch used for the graphic.
Anyone have any advice? Layout snippet below:
<TableRow>
<Spinner
android:id="#+id/spinnerPostPage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_column="1" />
</TableRow>
UPDATE: Full layout below - no styling external to this layout is used:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg">
<RelativeLayout
android:id="#+id/layoutHeader"
android:layout_width="fill_parent"
android:layout_height="55dp"
android:padding="10dp"
android:background="#008db9" >
<TextView
android:id="#+id/textViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="#string/create_a_craze"
android:textSize="24dp" />
<Button
android:id="#+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginRight="5dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="#string/save" />
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/layoutHeader" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:id="#+id/layoutBody"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/layoutHeader"
android:padding="5dp" >
<TableRow>
<TextView
android:id="#+id/textViewCrazeTitleLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#a1a0a3"
android:text="#string/craze_title_label" />
<EditText
android:id="#+id/editTextCrazeTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLength="50"
android:hint="#string/craze_title"/>
</TableRow>
<TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" >
<Button
android:id="#+id/buttonAddImage"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:text="#string/add_image" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:gravity="center" >
<ImageView
android:id="#+id/imageViewThumbnailOne"
android:layout_width="fill_parent"
android:layout_height="75dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:visibility="gone" />
<ImageView
android:id="#+id/imageViewThumbnailTwo"
android:layout_width="fill_parent"
android:layout_height="75dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:visibility="gone" />
<ImageView
android:id="#+id/imageViewThumbnailThree"
android:layout_width="fill_parent"
android:layout_height="75dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:visibility="gone" />
</LinearLayout>
</TableRow>
<TableRow>
<CheckBox
android:id="#+id/checkBoxShareLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:textColor="#a1a0a3"
android:text="#string/share_location_map"
android:textSize="12dp" />
</TableRow>
<TableRow>
<TextView
android:id="#+id/textViewPostToLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#a1a0a3"
android:text="#string/post_title_label" />
<Spinner
android:id="#+id/spinnerPostOptions"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</TableRow>
<TableRow>
<Spinner
android:id="#+id/spinnerPostPage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_column="1" />
</TableRow>
<TableRow>
<TextView
android:id="#+id/textViewShareCrazeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_gravity="center_vertical"
android:textColor="#a1a0a3"
android:text="#string/share_craze_label" />
<Spinner
android:id="#+id/spinnerPrivacySettings"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_column="1" />
</TableRow>
<TableRow>
<TextView
android:id="#+id/textViewCrazeDescriptionLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#a1a0a3"
android:text="#string/craze_description_label" />
</TableRow>
</TableLayout>
<EditText
android:id="#+id/editTextCrazeDescription"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_below="#id/layoutBody"
android:minLines="3"
android:maxLines="5"
android:inputType="textMultiLine" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>

Related

table layout problemss in custom listview android

I created a custom list view with table layout.
Now I want to show the text on the right. (You can see an example in the image, I cannot put this in the post)
But I cannot move textviews to the right.
http://i.stack.imgur.com/x57ly.png
my code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:background="#drawable/bar_bg"
android:paddingTop="0dip" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
tools:ignore="RtlHardcoded" >
<TableRow
android:layout_marginTop="3dp"
tools:ignore="UselessParent"
>
<LinearLayout
android:layout_width="120dp"
android:layout_height="82dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingTop="5dp"
tools:ignore="RtlSymmetry" >
<ImageView
android:id="#+id/image"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="left|top"
android:scaleType="centerCrop"
tools:ignore="ContentDescription" />
</LinearLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:paddingTop="0dp" >
<TableRow
android:layout_width="fill_parent"
android:layout_gravity="center_vertical"
android:textDirection="rtl"
tools:ignore="UnusedAttribute" >
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginLeft="5dp"
android:layout_marginTop="9dp"
android:layout_marginBottom="10dp"
android:paddingRight="6dp"
android:gravity="right"
android:layout_span="1"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="16sp" />
</TableRow>
<TableRow android:layout_width="fill_parent" >
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right"
android:paddingRight="6dp"
android:textColor="#000000"
android:textSize="16sp"
tools:ignore="RtlHardcoded" />
</TableRow>
</TableLayout>
</TableRow>
</TableLayout>
<TextView
android:id="#+id/tvdarsad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="16dp"
android:textSize="22sp"
android:textAlignment="center"
android:textStyle="bold"
android:layout_marginTop="18dp"
android:background="#drawable/badge_ifaux"
android:text="%20"
android:textColor="#FFFFFF" />
<ImageView
android:id="#+id/imagecolor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="15dp"
android:layout_marginRight="4dp"
android:layout_alignParentTop="true"
android:src="#drawable/color1"/>
</RelativeLayout>
I think you implemented a complicated solution. You can achieve the same result using LinearLayout and distributing the weight between its views.
Here I post you have an example with your code with the same result of the photo.
Hope it helps.
<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="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<ImageView
android:id="#+id/image"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
tools:ignore="ContentDescription" />
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="2"
android:layout_marginLeft="20dp"
android:orientation="vertical">
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="text1"
android:textColor="#000000"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="text2"
android:textColor="#000000"
android:textSize="16sp" />
</LinearLayout>
<TextView
android:id="#+id/text2"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".3"
android:textColor="#000000"
android:textSize="16sp" />
<ImageView
android:id="#+id/imagecolor"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".2"
android:src="#drawable/abc_btn_borderless_material"/>
</LinearLayout>

SlidingDrawer And ScrollView

I have a SlidingDrawer. And I want use ScrollView in my SlidingDrawer. I Try but app is not running.
I am tried ScrollView in LinearLayout but still not running app.
How can I do this.
Here İs Code:
.
.
.
.
.
.
<LinearLayout
android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<SlidingDrawer
android:layout_width="wrap_content"
android:layout_height="330dp"
android:content="#+id/content"
android:handle="#+id/handle"
android:id="#+id/slidingDrawer"
android:layout_gravity="center_horizontal"
android:padding="10dip">
<Button
android:id="#+id/handle"
android:layout_width="200dp"
android:layout_height="33dp"
android:text="== ÇÖZÜM =="
android:textSize="10dp"/>
<!-- I Try Add LinearLayout here But still not ronning.-->
<ScrollView
android:id="#+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#ababab"
android:gravity="center|top"
android:padding="10dip">
.
.
.
.
.
.
</ScrollView>
</SlidingDrawer>
</LinearLayout>
THANKS!
This is my layout design that i had used in one of my project and it worked perfect check this :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.wholesaleraja.touch_image.TouchImageZoom
android:id="#+id/singe_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:src="#drawable/raja" />
<RelativeLayout
android:id="#+id/det"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/single_item_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="5dp"
android:text="Single Name"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<View
android:id="#+id/view"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="#+id/single_item_text"
android:background="#color/list_divider" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/view"
android:orientation="horizontal" >
<TextView
android:id="#+id/code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Product Code : "
android:textColor="#000000"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/code_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:textColor="#000000"
android:textSize="14sp" />
</LinearLayout>
<Button
android:id="#+id/price_tag"
style="#style/button_text"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:background="#drawable/price_button_background"
android:clickable="false"
android:padding="5dp"
android:text="Price"
android:textColor="#ffffff" />
</RelativeLayout>
<SlidingDrawer
android:id="#+id/SlidingDrawer"
android:layout_width="fill_parent"
android:layout_height="400dp"
android:layout_alignParentBottom="true"
android:content="#+id/contentLayout"
android:handle="#+id/slideButton"
android:orientation="vertical"
android:padding="0dip"
android:rotation="0" >
<ImageView
android:id="#+id/slideButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/up" />
<ScrollView
android:id="#+id/contentLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#e5e5e5" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="7dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lot Size : "
android:textSize="15sp" />
<TextView
android:id="#+id/lot_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1 "
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Piece(s)/Lot"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="10dp" >
<TableLayout
android:id="#+id/details"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/list_divider"
android:orientation="vertical"
android:stretchColumns="*" >
<TableRow
android:id="#+id/row3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Lot(s) "
android:textSize="22sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Discount"
android:textSize="22sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Price/Lot"
android:textSize="22sp" />
</TableRow>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/list_divider" />
</TableLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Lot Qty : "
android:textSize="18sp" />
<Button
android:id="#+id/minus"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:background="#drawable/round_button"
android:text="-"
android:textSize="30sp"
android:textStyle="bold" />
<EditText
android:id="#+id/count"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/round_edittext"
android:focusable="false"
android:gravity="center"
android:inputType="number" >
</EditText>
<Button
android:id="#+id/plus"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/round_button"
android:text="+"
android:textSize="30sp"
android:textStyle="bold" />
</LinearLayout>
<Button
android:id="#+id/addtocart"
style="#style/button_text"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:background="#drawable/cart_button_background"
android:padding="5dp"
android:text="Add to Cart"
android:textColor="#ffffff" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/list_divider" />
<TextView
android:id="#+id/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="7dp"
android:text="Description"
android:textSize="20sp"
android:textStyle="bold" />
<View
android:layout_width="fill_parent"
android:layout_height="1.5dp"
android:background="#color/list_divider" />
<TextView
android:id="#+id/full_desc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="5dp"
android:paddingBottom="5dp"
android:textSize="15sp" />
</LinearLayout>
</ScrollView>
</SlidingDrawer>
</RelativeLayout>
</FrameLayout>

Android layout is missing elements when debugging on phone

I am experiencing some strange behaviour with my layouts. As you can see from the screenshot below (of the layout in eclipse) the 'register' button appears just fine at the bottom of the screen.
Before
However, if you now take a look at the following screenshot taken on my phone (HTC ONE X) whilst debugging, the button is completely cut off with plenty of space.
After
The code for the register page is as follows (where the button is contained within the relative layout)
<?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="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="Register"
android:textSize="18sp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Title:" />
<EditText
android:id="#+id/txtTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_weight="0.75"
android:ems="10"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="First Name:" />
<EditText
android:id="#+id/txtFirstName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_weight="0.75"
android:ems="10"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Surname:" />
<EditText
android:id="#+id/txtSurname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_weight="0.75"
android:ems="10"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Email:" />
<EditText
android:id="#+id/txtEmail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_weight="0.75"
android:ems="10"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Age:" />
<EditText
android:id="#+id/txtAge"
android:layout_width="10dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_weight="0.75"
android:ems="10"
android:text="" />
</LinearLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:stretchColumns="*"
android:weightSum="4" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/txtGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Gender" />
<TextView
android:id="#+id/txtTypeOfUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Type of User" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<RadioGroup
android:id="#+id/radioSex"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Male" />
<RadioButton
android:id="#+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>
<RadioGroup
android:id="#+id/radioTypeOfUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radioUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="User" />
<RadioButton
android:id="#+id/radioDoctor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Doctor" />
</RadioGroup>
</TableRow>
</TableLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="20dp"
android:layout_marginRight="20dp"
android:text="Register" />
</RelativeLayout>
</LinearLayout>
Your TableLayout has layout_height set to fill_parent, change it to wrap_content.
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:stretchColumns="*"
android:weightSum="4" >

How to align ImageView & TextView align right in a Linear Layout

I would like show my Page view header like below,
I'm using the following layout using, but the image and second textview not moving to right, its all align center.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="6"
android:background="#drawable/transbg"
android:gravity="center"
android:orientation="vertical" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="6"
android:gravity="center"
>
<TextView
android:id="#+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Magasin"
android:textColor="#FFF"
android:textSize="18sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:src="#drawable/yellow2" />
<TextView
android:id="#+id/tvCredits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="test"
android:textColor="#fff"
android:textSize="16sp" />
</LinearLayout>
</TableRow>
</LinearLayout>
</LinearLayout>
how I can align one image view and textview right aligned.
Check out this one and let me know if it is what you want.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="6"
android:background="#drawable/ic_launcher"
android:gravity="center"
android:orientation="vertical" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="6"
android:background="#android:color/black"
android:gravity="center" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Magasin"
android:textColor="#FFF"
android:textSize="18sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:src="#drawable/ic_launcher"
android:layout_toLeftOf="#+id/tvCredits" />
<TextView
android:id="#+id/tvCredits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="test"
android:textColor="#fff"
android:textSize="16sp" />
</RelativeLayout>
</TableRow>
</LinearLayout>
EDIT : If you want to make the same layout with easier and more efficient way, you can use this one.
<?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"
android:background="#android:color/black" >
<TextView
android:id="#+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Magasin"
android:textColor="#FFF"
android:textSize="18sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/tvCredits"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/tvCredits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="test"
android:textColor="#fff"
android:textSize="16sp" />
</RelativeLayout>
// try this way
<?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="wrap_content"
android:gravity="center"
android:padding="5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/txtName"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Magasin"
android:textColor="#FFF"
android:gravity="center"
android:textSize="18sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:adjustViewBounds="true"/>
<TextView
android:id="#+id/tvCredits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
android:textColor="#fff"
android:textSize="16sp"
android:layout_marginLeft="5dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="right">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="6"
android:background="#drawable/transbg"
android:gravity="center"
android:orientation="vertical" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="6"
android:gravity="center"
>
<TextView
android:id="#+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Magasin"
android:textColor="#FFF"
android:textSize="18sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="right|center"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:src="#drawable/yellow2" />
<TextView
android:id="#+id/tvCredits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="test"
android:textColor="#fff"
android:textSize="16sp" />
</LinearLayout>
</TableRow>
</LinearLayout>
</LinearLayout>
</LinearLayout>

Android Grid with LinearLayout

I'm trying to build a grid with some linear layouts.
Unfortunately the buttons inside the "grid" fill all the space and the "grid" isn't always the same size.
<ScrollView
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_weight="1">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/banner"
android:background="#80000000"
android:contentDescription="#string/about"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="15dp"
android:gravity="center_horizontal"
android:text="#string/modi1"
tools:context=".MenuActivity" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="15dp"
android:gravity="center_horizontal"
android:text="#string/modi2"
tools:context=".MenuActivity" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_marginTop="10dp"
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/szen_diagramm" />
<Button
android:layout_marginTop="10dp"
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/szen_countdown" />
</LinearLayout>
<Button
android:layout_marginTop="10dp"
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/szen_diagramm" />
<Button
android:layout_marginTop="10dp"
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/szen_countdown" />
</LinearLayout>
<Button
android:layout_marginTop="10dp"
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/szen_diagramm" />
<Button
android:layout_marginTop="10dp"
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/szen_countdown" />
</LinearLayout>
</LinearLayout>
</ScrollView>
It should look something like
this
with the buttons centered and at the size they need with the text inside.
Could anyone help me?
Try this.
<ScrollView xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableRow>
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#80000000"
android:contentDescription="ImageView"
android:layout_span="2"
android:src="#drawable/banner" />
</TableRow>
<TableRow>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="2"
android:gravity="center_horizontal"
android:text="modi1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="2"
android:gravity="center_horizontal"
android:text="modi2" />
</TableRow>
<TableRow>
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:gravity="center"
android:text="szen_diagramm" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:gravity="center"
android:text="szen_countdown" />
</TableRow>
<TableRow>
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:gravity="center"
android:text="szen_diagramm" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:gravity="center"
android:text="szen_countdown" />
</TableRow>
<TableRow>
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:gravity="center"
android:text="szen_diagramm" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:gravity="center"
android:text="szen_countdown" />
</TableRow>
</TableLayout>
this is how it shows to me
Remove the android:layout_weight="1" to avoid the button filling all the space.
You should try using a TableLayout and several TableRow to replace your LinearLayouts containing the buttons, thus creating a well formated grid
I had a similar problem, solved inserting a LinearLayout in TableRow. Have a look to the posted xml code and verify if it fits your requirements.
<TableRow
android:layout_gravity="fill_horizontal"
android:paddingTop="#dimen/table_row_padding_top" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_horizontal"
android:orientation="vertical" >
<ImageButton
android:contentDescription="#string/str_phone"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/icon_phone" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:text="#string/str_phone"
android:textColor="#000000"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_horizontal"
android:orientation="vertical" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/icon_car"
android:contentDescription="#string/str_car" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:text="#string/str_car"
android:textColor="#000000"
android:textSize="12sp" />
</LinearLayout>
</TableRow>

Categories

Resources