I'm New to Android and want to customize the spinner in an app I'm making.
This is what I want my spinners to look like http://prntscr.com/bk4pbt. I tried setting the background of the spinner to an image of the shape but it not looking how i want it to be.
<TextView
android:id="#+id/textViewStore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="Store:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/text" />
<Spinner
android:id="#+id/store_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:prompt="#string/store_prompt" />
Related
I try to align four checkboxes but one is not in the center of the other. If I shorten the text it fits but if its longer it looks like in the screenshot. The problem is it will be in different languages so the text size can be different. Also if I remove the scale it fits perfect but I need this bigger checkboxes
This is my code:
<CheckBox
android:id="#+id/cb1"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:text="#string/unmounted"
android:textColor="#color/textBlack"
android:layout_below="#+id/abc"
android:layout_toEndOf="#+id/imageView6"
android:focusable="false"/>
<CheckBox
android:id="#+id/cb2"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/problem_not_working"
android:textColor="#color/textBlack"
android:layout_below="#+id/cb1"
android:layout_alignStart="#+id/cb1"
android:focusable="false"/>
<CheckBox
android:id="#+id/cb3"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/problem_cable_defective"
android:textColor="#color/textBlack"
android:layout_below="#+id/cb2"
android:layout_alignStart="#+id/cb2"
android:focusable="false"/>
<CheckBox
android:id="#+id/cb4"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/problem_cable_tie"
android:textColor="#color/textBlack"
android:layout_below="#+id/cb3"
android:layout_alignStart="#+id/cb3"
android:focusable="false"/>
Here is the exact solution for your problem, the thing which you are actually trying to achieve is the bigger checkbox view (corresponding to its text which is as big as the checkbox view, obviously) with proper alignment of all the views in the series, something like this:
Your desired UI.
But the thing you are doing wrong is that you are using the scaleX and scaleY attributes for achieving your desired UI that distorts your view as these two attributes scale the complete view i.e. the squared checkbox view with its text/label in the X and Y directions respectively (together with the text/label of the checkbox), so there is a dependency on the text as well (which is distorting your view).
So, the below code will solve your problem:
(In this I have taken the squared checkbox view as separate and beside it I have placed a textview in which I have written the text which corresponds to the text/label of that checkbox to complete the UI). Thereby using two views (i.e. the CheckBox and the TextView beside it) instead of using a single compound view (i.e. the CheckBox).
Note: In the solution given below, the CheckBox is a compound view but I haven't used it in the
same manner.
<?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">
<View
android:id="#+id/some_view"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="20dp"
android:layout_marginTop="23dp" />
<!--android:text="Unmounted"-->
<CheckBox
android:id="#+id/cb1"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="23dp"
android:layout_below="#+id/some_view"
android:layout_alignStart="#+id/some_view"
android:focusable="false" />
<TextView
android:id="#+id/tv_for_cb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#id/cb1"
android:layout_alignTop="#+id/cb1"
android:layout_alignBottom="#+id/cb1"
android:layout_marginStart="40dp"
android:text="Unmounted"
android:textColor="#android:color/black"
android:textSize="24sp" />
<!--android:text="Problem Not Working"-->
<CheckBox
android:id="#+id/cb2"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:layout_below="#+id/cb1"
android:layout_alignStart="#+id/cb1"
android:focusable="false"/>
<TextView
android:id="#+id/tv_for_cb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#id/cb2"
android:layout_alignTop="#+id/cb2"
android:layout_alignBottom="#+id/cb2"
android:layout_marginStart="40dp"
android:text="Problem Not Working"
android:textColor="#android:color/black"
android:textSize="24sp" />
<!--android:text="Problem Cable Defective"-->
<CheckBox
android:id="#+id/cb3"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:layout_below="#+id/cb2"
android:layout_alignStart="#+id/cb2"
android:focusable="false"/>
<TextView
android:id="#+id/tv_for_cb3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#id/cb3"
android:layout_alignTop="#+id/cb3"
android:layout_alignBottom="#+id/cb3"
android:layout_marginStart="40dp"
android:text="Problem Cable Defective"
android:textColor="#android:color/black"
android:textSize="24sp" />
<!--android:text="Problem Cable Tie"-->
<CheckBox
android:id="#+id/cb4"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:layout_below="#+id/cb3"
android:layout_alignStart="#+id/cb3"
android:focusable="false"/>
<TextView
android:id="#+id/tv_for_cb4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#id/cb4"
android:layout_alignTop="#+id/cb4"
android:layout_alignBottom="#+id/cb4"
android:layout_marginStart="40dp"
android:text="Problem Cable Tie"
android:textColor="#android:color/black"
android:textSize="24sp" />
</RelativeLayout>
And the other way out to your mentioned problem would be to create custom drawables for the checkbox and then handle them using a state list drawable as for the checkbox to be shown differently in different states as when it is unchecked, checked etc.
This link would help you if you are interested in doing it in this manner or way and would be great if you want to customize your checkbox's view.
Creating custom checkbox using selectors and shapes.
For further help in this context refer:
Android: How to change CheckBox size?
I have used 2 spinners in my android activity,one is for country and other is for states,country spinner displays data as dropDown List(down side),But the state spinner gives me data enlisted to upside as shown in image.I want to display it same as country spinner(down side),Please help me.my spinner code is as below:
code
<Spinner
android:id="#+id/spr_country"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_cntry_id"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:spinnerMode="dropdown" />
<Spinner
android:id="#+id/spr_states"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/spr_country"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:spinnerMode="dropdown" />
Spinner does not have Sufficient space to display spinner popup to downside. Android system will automatically popup it to upside.
I am trying to create a Button that looks like a Spinner.
I have done this by creating a Button like this:
<Button
android:id="#+id/dateButton"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/dateLabel"
android:text="default text"
android:textSize="15sp"
style="?android:attr/spinnerStyle"
android:gravity="center_vertical|center_horizontal" />
The problem is that the text ("default text") inside the Button seems to have extra padding around it, which makes the Button look bloated and expanded in its height.
I thought that setting the layout_height for the button to "wrap_content" would fix this and make the button thinner, but it does not have any effect.
Does anyone know how to make this button's height wrap to the text inside it?
Here is the example code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="10dp" >
<TextView
android:id="#+id/dateLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:text="Select date:"
android:textSize="15sp" />
<Button
android:id="#+id/dateButton"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/dateLabel"
android:text="default text"
android:textSize="15sp"
style="?android:attr/spinnerStyle"
android:gravity="center_vertical|center_horizontal" />
</RelativeLayout>
android:gravity="center_vertical|center_horizontal" instead of this you can write
android:gravity="center" but as per your requirment just remove this line.do not add any gravity and change your height size android:layout_height="40dp"
i changed your code
<Button
android:id="#+id/dateButton"
android:layout_width="150dp"
android:layout_height="35dp"
android:layout_toRightOf="#+id/dateLabel"
android:text="default text"
style="?android:attr/spinnerStyle"
/>
The padding of this button is decided by the drawable of it. You either need to change the spinner drawable (can be done at runtime) , or provide your own drawable to the given button that would make it look like a spinner, without using the default one
I want to make one application which contains multiple choice question. Each question has three option. I want to show that option with one background image. And also want to change the color of that image randomly for each question. How can i do that?
It is possible to create list view by putting differnt background image for each row?
Result.xml
<LinearLayout
android:id="#+id/linearlayoutans"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="30dp"
android:layout_toLeftOf="#+id/chrono"
android:orientation="horizontal" >
<TextView
android:id="#+id/txt_ans_true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:gravity="center"
android:textColor="#000000" />
<TextView
android:id="#+id/txt_ans_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:gravity="center"
android:textColor="#000000" />
<TextView
android:id="#+id/txt_ans_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:gravity="center"
android:textColor="#000000" />
</LinearLayout>
It is possible to create list view by putting differnt background
image for each row?
Yes. Take a look at articles on the internet that back a listview with a custom adapter and a custom view. This is done from the getView() method and there is no shortage of examples / tutorials out there.
I am trying to modify the design of Spinner widget. I can change the background, but I can't find a way to change the arrow icon on the right side. Is there a way to do it?
Thanks!
The whole thing is a single 9 patch png image. I've modified the entire look of spinners before by replacing the images. See this page: http://androiddrawableexplorer.appspot.com/
Specifically look at btn_dropdown_normal.9, btn_dropdown_pressed.9, btn_dropdown_selected.9 and btn_dropdown_disabled.9
You just need to provide your own versions of those images.
Also, you can place your "spinner bar" layout in a FrameLayout, together with the real spinner but set to invisible:
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="32dip"
>
<Spinner
android:id="#+id/theSpinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="32dip"
android:background="#drawable/my_background"
android:padding="6dip"
android:clickable="true"
android:onClick="spinnerBarReplacementClicked"
>
<ImageView
android:id="#+id/replacementSelectImg"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/my_drawable"
/>
<TextView
android:id="#+id/replacementSelectText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="4dip"
android:layout_toLeftOf="#id/replacementSelectImg"
android:textColor="#000000"
android:textSize="14sp"
android:ellipsize="marquee"
android:singleLine="true"
/>
</RelativeLayout>
</FrameLayout>
and pass the clicks from your layout to the real spinner
private Spinner mSpinner;
mSpinner = (Spinner) findViewById(R.id.theSpinner);
public void spinnerBarReplacementClicked(View pV){
mSpinner.performClick();
}