XML Spinner attributes textAlignment = “right” API 16

By : Jeremy
Source: Stackoverflow.com
Question!

I'm trying to set attributes to a spinner on my android app and one of the attributes in textAlignment = "right" (the problem being I've a spinner that layout_width="match_parent" so there's a lot a space and I'd like to have it to the right) but this is only supported in API 17 and up whereas I want to make an app for API 16 - Is there a work-around?

My attributes are:

        <Spinner
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:textAlignment="gravity"
            android:id="@+id/MainSpinner"
            tools:listitem="@layout/support_simple_spinner_dropdown_item"/>

The current linearLayout looks like this:

enter image description here

And I want it to look like this:

enter image description here

Where:

LinearLayout (horizontal) = enter image description here

RelativeLayout = enter image description here

TextView = enter image description here

LinearLayout (Vertical) = enter image description here

Spinner = enter image description here

Button = enter image description here

By : Jeremy


Answers

This ans work for me...

<Spinner
android:id="@+id/example_spinner"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:textAlignment="right"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="2dp"
android:paddingBottom="2dp" />

I've followed this : http://nevescheng.blogspot.fr/2013/05/spinner-with-item-text-aligned-to-center.html & this worked fine...



Looks like in your code the gravity(not layout_gravity) attribute determines the alignment. Try replacing

android:layout_gravity="right"
android:textAlignment="gravity"

with

android:gravity="right"


Just use jquery. It's easy fun and extensible. Don't try bizzare uses. Be sure all the time to be compatible through all the browser. If you copy this and run it under a local or remote webserver will work like a charm. Cheers.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $.ajax({url: "test.txt", success: function(result){
            $("#div1").html(result);
        }});
    });
});
</script>
</head>
<body>

<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>

<button>Get External Content</button>

</body>
</html>


This video can help you solving your question :)
By: admin