Center Editext in a Linear Layout - Android - android

I'm trying to center the editText which you can see in this screen (the one on the black buttons):
This is my code. I set the android:gravity="center_horizontal" tag, but as you can see it doesn't works. I do not understand if I need to set it at the center of its linear layout or if I need to pay attention to the external linear layout:
<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:background="#FCFCFC"
android:orientation="vertical"
android:layout_marginTop="8dp"
tools:context=".PaintingActivity" >
<!-- Top Buttons -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/draw_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="50dp"
android:contentDescription="#string/brush"
android:background="#drawable/rounded_corners"
android:padding="16dp"
android:layout_marginTop="5dp"
android:src="#drawable/brush" />
<ImageButton
android:id="#+id/erase_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="50dp"
android:contentDescription="#string/erase"
android:background="#drawable/rounded_corners"
android:padding="16dp"
android:layout_marginTop="5dp"
android:src="#drawable/eraser" />
<ImageButton
android:id="#+id/undo_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="Undo"
android:layout_marginRight="50dp"
android:background="#drawable/rounded_corners"
android:padding="16dp"
android:layout_marginTop="5dp"
android:src="#drawable/undo" />
<ImageButton
android:id="#+id/colorPicker"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corners"
android:contentDescription="colorPicker"
android:padding="16dp"
android:src="#drawable/palette" />
</LinearLayout>
<!-- Custom View -->
<com.example.williamstest.DrawingView
android:id="#+id/drawing"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginBottom="3dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"
android:layout_weight="1"
android:background="#FFFFFFFF" />
<!-- Menu in basso -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical" >
<!-- Top Row -->
<LinearLayout
android:id="#+id/toprow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/_70sdp"
android:orientation="horizontal">
<EditText
android:id="#+id/edittitle"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:layout_marginTop="15dip"
android:layout_marginBottom="25dip"
android:ems="10"
android:hint="Inserisci qui il titolo"
android:gravity="center_horizontal"
android:inputType="textNoSuggestions"
android:singleLine="true"/>
</LinearLayout>
<!-- Bottom Row -->
<LinearLayout
android:id="#+id/bottomrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="120dp"
android:orientation="horizontal">
<Button
android:id="#+id/bb_3"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginLeft="120dp"
android:layout_marginBottom="10dp"
android:background="#drawable/button_bg"
android:text="Indietro"
android:textColor="#FFFFFF" />
<Button
android:id="#+id/bb_2"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginLeft="120dp"
android:layout_marginBottom="10dp"
android:layout_weight="1"
android:background="#drawable/button_bg"
android:text="Avanti"
android:textColor="#FFFFFF" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

You have a redundant left margin
Remove android:layout_marginLeft="#dimen/_70sdp"from thetoprowlayout
or add an equal right margin

No need to use layout_marginLeft to align it center_horizontal, remove it. Just add android:gravity to center_horizontal in your LinearLayout enclosing EditText.
<LinearLayout
android:id="#+id/toprow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<EditText
android:id="#+id/edittitle"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:layout_marginTop="15dip"
android:layout_marginBottom="25dip"
android:ems="10"
android:hint="Inserisci qui il titolo"
android:gravity="center_horizontal"
android:inputType="textNoSuggestions"
android:singleLine="true"/>
</LinearLayout>

Related

relative layout gravity center not aligning correctly

I'm trying to center the chilldren of my relative layout in the center of my screen but it's acting like it's aligned to the top of the parent and I can't figure out why.
my .XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="#f70909">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:adjustViewBounds="true"
android:src="#drawable/dice"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textMessage"
android:layout_centerHorizontal="true"
android:layout_below="#+id/imageView2" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editUserSplash"
android:hint="Username"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_below="#+id/textMessage" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editPasswordSplash"
android:hint="Password"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_below="#+id/editUserSplash" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/btnSplash"
android:layout_centerHorizontal="true"
android:layout_below="#+id/editPasswordSplash" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/prgSplash"
style="#android:style/Widget.DeviceDefault.ProgressBar.Large"
android:layout_centerHorizontal="true"
android:indeterminate="true"
android:layout_below="#+id/btnSplash" />
</RelativeLayout>
I've tried making the parent a relativelayout without success and it won't align to the bottom either. Initially I thought the layout wasn't filling the whole screen but since its height and width are match_parent I don't think that's the problem. in android studio it is displaying correctly though so I must be missing something small.
I also tried using the gravity and layoutgravity parameters and a combination of the two but without success
Edit: I need the views to stay in the same formation relative to each other but centered in the screen vertically.
Edit 2:I set the background of the RelativeLayout to red and got this: So the relativelayout isn't filling my screen.
Edit 3:
Edit 4:
try this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f70909">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:adjustViewBounds="true"
android:src="#drawable/dice"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textMessage"
android:layout_centerHorizontal="true"
android:layout_below="#+id/imageView2" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editUserSplash"
android:hint="Username"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_below="#+id/textMessage" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editPasswordSplash"
android:hint="Password"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_below="#+id/editUserSplash" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/btnSplash"
android:layout_centerHorizontal="true"
android:layout_below="#+id/editPasswordSplash" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/prgSplash"
style="#android:style/Widget.DeviceDefault.ProgressBar.Large"
android:layout_centerHorizontal="true"
android:indeterminate="true"
android:layout_below="#+id/btnSplash" />
</RelativeLayout>
</RelativeLayout>
Try something like this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:adjustViewBounds="true"
android:layout_centerInParent="true"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_centerInParent="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textMessage" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editUserSplash"
android:hint="Username"
android:gravity="center" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editPasswordSplash"
android:hint="Password"
android:gravity="center" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/btnSplash" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/prgSplash"
style="#android:style/Widget.DeviceDefault.ProgressBar.Large"
android:indeterminate="true" />
</LinearLayout>
</RelativeLayout>
UPDATE:
If setting the xml in an AlertDialog, it's possible that there is a space allotted at the bottom. I google and found this alert_dialog.xml for reference. It seems that there is a buttonPanel at the bottom with a minimum height of 54dip.
<LinearLayout android:id="#+id/buttonPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="54dip"
android:orientation="vertical" >
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="4dip"
android:paddingStart="2dip"
android:paddingEnd="2dip"
android:measureWithLargestChild="true">
<LinearLayout android:id="#+id/leftSpacer"
android:layout_weight="0.25"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone" />
<Button android:id="#+id/button1"
android:layout_width="0dip"
android:layout_gravity="start"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:maxLines="2"
android:layout_height="wrap_content" />
<Button android:id="#+id/button3"
android:layout_width="0dip"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:maxLines="2"
android:layout_height="wrap_content" />
<Button android:id="#+id/button2"
android:layout_width="0dip"
android:layout_gravity="end"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:maxLines="2"
android:layout_height="wrap_content" />
<LinearLayout android:id="#+id/rightSpacer"
android:layout_width="0dip"
android:layout_weight="0.25"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
I think this may help you
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center">
<RelativeLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/textMessage"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editUserSplash"
android:hint="Username"
android:layout_below="#+id/textMessage"
android:gravity="center" />
<EditText
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editPasswordSplash"
android:hint="Password"
android:layout_below="#+id/editUserSplash"
android:gravity="center" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/btnSplash"
android:layout_below="#+id/editPasswordSplash"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Thanks to ank I was able to figure out that the reason why the RelativeLayout didn't fill my screen is that I used it in an alertDialog. So RelativeLayouts parent isn't the screen but the alertDialog. Since an alertDialog wraps its content it doesn't fill the entire screen.

Center a TextView below an ImageView in a TableLayout

how can I center a TextView below an ImageView in a TableLayout? I see that I have to use center_horizontal with a specified layout_width in dp:
android:layout_width="90dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
...but my text value is not always the same, I set it programmatically and if it's too long:
So I set android:singleLine to true:
android:layout_width="90dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:singleLine="true"
So I set layout_width to wrap_content but in this way center_horizontal is not working :(
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:singleLine="true"
This is my TableRow layout:
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/table_row_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp">
<RelativeLayout
android:id="#+id/relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<!-- Left column -->
<ImageView
android:id="#+id/left_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:src="#drawable/item_image" />
<TextView
android:id="#+id/left_name"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/left_image"
android:layout_alignStart="#+id/left_image"
android:layout_below="#+id/left_image"
android:gravity="center_horizontal"
android:text="ITEM TEXT VIEW"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/black" />
<!-- Right column -->
<ImageView
android:id="#+id/right_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/left_name"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="60dp"
android:layout_marginRight="60dp"
android:src="#drawable/item_image"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/right_name"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/right_image"
android:layout_alignStart="#+id/right_image"
android:layout_below="#+id/right_image"
android:gravity="center_horizontal"
android:text="ITEM TEXT VIEW" />
</RelativeLayout>
</TableRow>
Anyone can help me?
UPDATE: This my real layout element:
You can use two RelativeLayouts instead of one. Check this XML,
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/table_row_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp">
<RelativeLayout
android:id="#+id/relative_layout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:weightSum="0.5">
<!-- Left column -->
<ImageView
android:id="#+id/left_image"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:src="#drawable/item_image" />
<TextView
android:id="#+id/left_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/left_image"
android:gravity="center_horizontal"
android:layout_centerHorizontal="true"
android:text="ITEM TEXT VIEW"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/black" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relative_layout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:weightSum="0.5">
<!-- Right column -->
<ImageView
android:id="#+id/right_image"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:src="#drawable/item_image" />
<TextView
android:id="#+id/right_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/right_image"
android:gravity="center_horizontal"
android:layout_centerHorizontal="true"
android:text="ITEM TEXT VIEW"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/black" />
</RelativeLayout>
</TableRow>
RelativeLayout is not a best suit for this scenario.It's better to replace with two LinearLayouts. The advantage is, you can avoid most of the magic numbers like margins and paddings. Try this layout,
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/table_row_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<!-- Left column -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/left_image"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/circle" />
<TextView
android:id="#+id/left_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="ITEM TEXT VIEW" />
</LinearLayout>
<!-- Right column -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/right_image"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/circle"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/right_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="ITEM TEXT VIEW" />
</LinearLayout>
</TableRow>

Position a LinearLayout (horizontal center)

I have a problem positioning a LinearLayout. See image for the problem. If I use wrap_content in the field specified, it is not centered. If I use match_parent, it is centered, but the components are spaced too far apart. How do I 'wrap' the contents, but center the layout horizontally? (vertical is not a consideration here)
<LinearLayout
android:layout_width="wrap_content" !!! (or match_parent)
android:layout_height="wrap_content"
android:layout_margin="25dip"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/game1CheckButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="4dp"
android:background="#null"
android:contentDescription="#string/checkbutton"
android:gravity="center"
android:onClick="clickCheck"
android:src="#drawable/checkbutton" />
</LinearLayout>
<TextView
android:id="#+id/game1Step"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="#string/game1step1"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="50sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/game1NextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="4dp"
android:background="#null"
android:clickable="false"
android:contentDescription="#string/nextbutton"
android:enabled="false"
android:gravity="center"
android:onClick="clickNext"
android:src="#drawable/nextbutton" />
</LinearLayout>
Try using android:layout_width="wrap_content" and android:layout_gravity="center_horizontal"
As far as I can understand, you want 3 obects all positioned in the horizontal center, no matter the vertical position.
So, I'd do that like this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="25dip"
>
<!-- The center object -->
<TextView
android:id="#+id/game1Step"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:contentDescription="#string/game1step1"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="50sp"
android:textStyle="bold"
/>
<!-- The left object -->
<ImageButton
android:id="#+id/game1CheckButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/game1Step"
android:layout_gravity="center"
android:layout_margin="4dp"
android:background="#null"
android:contentDescription="#string/checkbutton"
android:gravity="center"
android:onClick="clickCheck"
android:src="#drawable/checkbutton"
/>
<!-- The right object -->
<ImageButton
android:id="#+id/game1NextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/game1Step"
android:layout_gravity="center"
android:layout_margin="4dp"
android:background="#null"
android:clickable="false"
android:contentDescription="#string/nextbutton"
android:enabled="false"
android:gravity="center"
android:onClick="clickNext"
android:src="#drawable/nextbutton"
/>
</RelativeLayout>

Slim Spinner when i use FILL_PARENT (or MATCH_PARENT) as WIDTH

i've a strange problem when i set android:layout_width="fill_parent" in my Spinner:
the clickable area is reduced to a line (red square) and only pressing on this line is possibile show the elements of the Spinner:
if i use android:layout_width="wrap_content" i obtain the correct area:
i would like the same thing using "fill_parent"
The elements of the Spinner are correctly visualized.. The only problem is clicking on the Spinner.
Which is the possible problem?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#040404"
android:gravity="center"
android:paddingTop="2dp"
android:weightSum="4" >
<TextView
android:id="#+id/mpp_movimento_lbl"
android:background="#drawable/selector_black_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/freccia_verde"
android:gravity="center"
android:text="#string/Movimento"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="17sp" />
<TextView
android:id="#+id/mpp_eccesso_lbl"
android:background="#drawable/selector_black_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/freccia_rossa"
android:gravity="center"
android:text="#string/Eccesso"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="17sp" />
<TextView
android:id="#+id/mpp_fermo_lbl"
android:background="#drawable/selector_black_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/freccia_grigia"
android:gravity="center"
android:text="#string/Fermo"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="17sp" />
<TextView
android:id="#+id/mpp_ripristina_lbl"
android:background="#drawable/selector_black_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/ripristina_mappa_40x40"
android:gravity="center"
android:text="#string/Ripristina"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="17sp" />
</LinearLayout>
<TextView
android:id="#+id/mpp_automezzi_visualizzati_lbl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/black"
android:gravity="center"
android:paddingTop="5dp"
android:text="#string/AutomezziVisualizzati"
android:textColor="#color/white"
android:textSize="17sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:paddingTop="5dp" >
<FrameLayout
android:id="#+id/mpp_spinner_frame_fly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/mpp_cerca_btn" >
<Spinner
android:id="#+id/mpp_spinner_spn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textSize="17sp" />
</FrameLayout>
<ImageButton
android:id="#+id/mpp_cerca_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:background="#drawable/selector_white_btn"
android:contentDescription="#string/DescrizioneCerca"
android:gravity="center"
android:onClick="doCerca"
android:src="#drawable/cerca" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#040404"
android:gravity="center" >
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="#+id/mpp_mappa_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
Try setting your Spinner's parent's height to match_parent. And also do you really need such layout? There is no need to place spinner in FrameLayout, try setting spinners's weight to 1 and replace RelativeLayout with LinearLayout

Horizontal Scroll View inside LinearLayout - Android

I have a custom list. I am trying to scroll horizontally only specific part. For Instance, in the below image iam trying to scroll horizontally just the orange box.
Here is my XML Layout: In the XML layout the Orange box starts "android:id="#+id/projected"
<?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:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="63dp"
android:layout_marginLeft="0dp"
android:background="#drawable/bkg_img_fullcell"
android:orientation="horizontal" >
<!-- Left Column -->
<LinearLayout
android:id="#+id/widget_lineupview_playerdata_container"
android:layout_width="wrap_content"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:layout_toRightOf="#+id/sideView"
android:gravity="center_vertical"
android:layout_toLeftOf="#+id/projected"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4" >
<!-- rel 1 -->
<LinearLayout
android:id="#+id/playername1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_toRightOf="#+id/sideView">
<com.cbssports.nflapp.ffb.MyTextViewBold
android:id="#+id/widget_lineupview_playerdata_playername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:inputType="text|textNoSuggestions"
android:layout_marginLeft="5dp"
android:maxLines="1"
android:text=""
android:textColor="#08233e"
android:textSize="15dp" />
</LinearLayout>
<!-- rel 2 -->
<LinearLayout
android:id="#+id/widget_lineupview_playerdata_playerStatsIconContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_toRightOf="#+id/playername1"
android:orientation="horizontal" >
<ImageView
android:id="#+id/widget_lineupview_playerdata_statusIconSuspended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:src="#drawable/btn_s"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_toRightOf="#+id/sideView" >
<TextView
android:id="#+id/widget_lineupview_playerdata_playerPositionTeam"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:inputType="text|textNoSuggestions"
android:maxLines="1"
android:text=""
android:textColor="#333333"
android:textSize="12dp" />
<ImageView
android:id="#+id/widget_lineupview_playerdata_startingPitcherStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:src="#drawable/btn_baseballgraphic"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/sideView"
android:layout_width="#dimen/widget_lineup_table_status_column_width"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:layout_alignParentLeft="true"
android:background="#drawable/bkg_img_rosterpos"
android:gravity="center" >
<!-- <Button -->
<com.cbssports.nflapp.ffb.VerticalTextView
android:id="#+id/widget_lineupview_playerdata_playerStatusButton"
android:layout_width="21dp"
android:layout_height="60dp"
android:layout_margin="0dp"
android:padding="0dp"
android:textColor="#004a8e"
android:textSize="11dp"
android:textStyle="bold"
android:gravity="bottom|center" />
</LinearLayout>
***<LinearLayout
android:id="#+id/projected"
android:layout_width="wrap_content"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:background="#drawable/bkg_img_whiteoverlay"
android:layout_toLeftOf="#+id/percentStarted">
<TextView
android:id="#+id/widget_lineupview_player_h2h_stats_started_custom"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textStyle="bold"
android:textSize="16dp"
android:textColor="#333333" />
</LinearLayout>
<LinearLayout
android:id="#+id/percentStarted"
android:layout_width="wrap_content"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:background="#drawable/bkg_img_whiteoverlay"
android:layout_alignParentRight="true"
android:layout_marginLeft="2dp">
<TextView
android:id="#+id/widget_lineupview_player_projected_custom"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textStyle="bold"
android:textSize="16dp"
android:textColor="#333333" />
</LinearLayout>***
</RelativeLayout>
Thank You g00dy, i can able to solve it by adding one LinearLayout inside horizontalScrollView it.
Here is my solution.
<HorizontalScrollView
android:id="#+id/horizontalScroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:scrollbars="none">
<LinearLayout
android:id="#+id/horizontalScroll_linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentRight="true" >
<LinearLayout
android:id="#+id/projected"
android:layout_width="wrap_content"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:background="#drawable/bkg_img_whiteoverlay"
android:layout_toLeftOf="#+id/percentStarted">
<TextView
android:id="#+id/widget_lineupview_player_h2h_stats_started_custom"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textStyle="bold"
android:textSize="16dp"
android:textColor="#333333" />
</LinearLayout>
<LinearLayout
android:id="#+id/percentStarted"
android:layout_width="wrap_content"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:background="#drawable/bkg_img_whiteoverlay"
android:layout_alignParentRight="true"
android:layout_marginLeft="2dp">
<TextView
android:id="#+id/widget_lineupview_player_projected_custom"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textStyle="bold"
android:textSize="16dp"
android:textColor="#333333" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
You can also set the LinearLayout fillViewport to true and foregroundGravity to true (not sure if this last is necessary), and set the child LinearLayout gravity to right:
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="#dimen/IconM"
android:id="#+id/account_food_scroll"
android:layout_alignParentEnd="false"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/client_add_button_layout"
android:foregroundGravity="right"
android:layout_marginLeft="#dimen/PadM"
android:fillViewport="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="#dimen/IconM"
android:id="#+id/account_food_layout"
android:gravity="right">
</LinearLayout>
</HorizontalScrollView>

Categories

Resources