Custom spinner style - android-layout

How can I style/customize spinner like shown below using xml?
I can make white background with border, but i can't set icon on the left and arrow on the right.

If your problem is with a layout that sets the icon to the left and arrow to the right, the following should work.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/icon" />
<ImageView
android:id="#+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
</RelativeLayout>
I'm at work, so I can't test this out, but I think it should work.

Related

Scrollview overlaps part of the text

I need help.
At work, I was given a task to figure out why ScrollView overlaps part of the text. The layout is multi-layered, and I think the problem lies in this. I'm new to android studio and it's still hard for me to understand the relationships of all objects.
all the XML is here https://docs.google.com/document/d/1PaGIWPn2w6ubZraVpQfq8Rrqo0uCWYOiIbxnCWaIKTQ/edit?usp=sharing
below is a part of the code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|left|center_vertical"
android:orientation="vertical">
<TextView
android:id="#+id/tvMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp"
android:textColor="#color/mainBlackColor"
android:textSize="24dp"
tools:text="Сообщение" />
<TextView
android:id="#+id/tvDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/red"
android:lines="3"
android:paddingStart="3dp"
android:paddingLeft="3dp"
android:paddingTop="2dp"
android:paddingEnd="3dp"
android:paddingRight="3dp"
android:paddingBottom="2dp"
android:textColor="#color/mainTextColor"
android:textSize="18dp"
android:visibility="gone"
app:autoSizeMaxTextSize="18dp"
app:autoSizeMinTextSize="10dp"
app:autoSizeStepGranularity="4dp"
app:autoSizeTextType="uniform"
tools:text="Детали"
tools:visibility="visible" />
</LinearLayout>
</ScrollView>
Add android:scrollbarStyle="outsideOverlay" and padding_horizontal to your scrollView. This should solve your issue.

Android How to position Items in a Toolbar

I understand the one of the advantages of the toolbar over the action bar is the ability to position and add items. However I cannot figure out how to position these items on the toolbar where I would like to. I have 6 items and i want three of the items aligned to the left a space in the middle and the other three aligned to the right.
Use a Space widget for this.
Add a LinearLayout inside your Toolbar. I am adding 6 TextViews inside this LinearLayout. You can, of course, change it according to your requirement.
Now to align 3 of the child views to the left and 3 to the right simply add a android.support.v4.widget.Space widget after the third child view and set it's layout_weight property to 1.
Here's the entire toolbar layout
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="item1"
android:padding="2dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="item2"
android:padding="2dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="item3"
android:padding="2dp"/>
<android.support.v4.widget.Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="item4"
android:padding="2dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="item5"
android:padding="2dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="item6"
android:padding="2dp"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
Hope this works as required for you.

can't get android custom dialog box to size properly

I'm trying to create a custom dialog box but it's both making it as wide as the screen (minus padding) but more importantly it's adding about an inch to the top in white (the background colour is red) above the first textview. What I want is a dialog box just as big as it needs to fill the content.
If I change any layout from fill_parent to wrap_content I get the contents about the size of the image and everything else (i.e. the text) is truncated.
What am I doing wrong?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/customdialog"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/titledialog"
android:orientation="vertical" >
<TextView
android:id="#+id/textTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/titleback"
android:gravity="center"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/title" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="24dp"
android:paddingTop="48dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="TextView" />
</LinearLayout>
<Button
android:id="#+id/buttonCustomDialogOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Close" />
I found the answer here
Android: How to create a Dialog without a title?
Apparently the top blank bit is the title of the layout and you cannot get rid of it unless you use an AlertDialog and not a Dialog.
ah, thanks for the update.
Android Dialog: Removing title bar
you can do it like this
Dialog dialog = new Dialog(context, R.style.FullHeightDialog);
(OR Try This)
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

Android RelativeLayout with wrap_content too small to fit children

Here is a simple RelativeLayout with 4 controls arranged in a tabular format.
When displayed, the confirmpassword box is clipped at the bottom. It's as if "wrap_content" is not correctly calculating the height of the children. Any ideas?
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/passwordlabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="34dp"
android:text="Password"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/passwordlabel"
android:layout_alignLeft="#+id/confirmpassword"
android:layout_toRightOf="#id/passwordlabel"
android:ems="10"
android:inputType="textPassword" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/confirmpasslabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/passwordlabel"
android:layout_below="#id/passwordlabel"
android:text="Confirm Password"
android:layout_marginTop="34dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/confirmpassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/confirmpasslabel"
android:layout_toRightOf="#id/confirmpasslabel"
android:layout_marginLeft="15dp"
android:ems="10"
android:inputType="textPassword" />
</RelativeLayout>
This is what it looks like:
I have tried adding padding and/or margins to both of the bottom controls which has no effect (and strikes me as a hack anyway).
NB:- I had a similar problem before which a kindly soul solved essentially by splitting apart the RelativeLayout. I don't think that's possible here (it may be) but I'm concerned I'm either doing something completely wrong, or the RelativeLayout has a massive bug which seems under-documented.
Anyone able to shed light on this? TIA!
It does seem like a bit of a bug. I couldn't get it to work properly (without changing it somehow) with a RelativeLayout - something with the margins was throwing it off.
As a workaround, try a TableLayout:
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow android:layout_marginTop="34dp">
<TextView
android:id="#+id/passwordlabel"
android:text="Password"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/password"
android:ems="10"
android:inputType="textPassword" >
<requestFocus />
</EditText>
</TableRow>
<TableRow android:layout_marginTop="34dp">
<TextView
android:id="#+id/confirmpasslabel"
android:text="Confirm Password"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/confirmpassword"
android:layout_marginLeft="15dp"
android:ems="10"
android:inputType="textPassword" />
</TableRow>
</TableLayout>

Layout display problem on whenever i have to scroll

i want to display two buttons at the bottom of my activity screen, but each time i populate the screen with views that makes me scroll, the two buttons at the bottom of my screen disappears. when there is no need to scroll the buttons display fine.
please help
thanks.
Layout code
?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/lin_layout_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:isScrollContainer="true"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<ListView android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2px"
android:layout_gravity="bottom"
>
<TableLayout
android:layout_below="#id/lin_layout_list_view"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:layout_width ="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0,1">
<TableRow
android:orientation="horizontal">
<Button android:id="#+id/ws_button_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Back "
/>
<Button android:id="#+id/ws_button_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Ok "/>
</TableRow>
</TableLayout>
</RelativeLayout>
</LinearLayout>
Wrap the buttons along with the scrollable content(e.g:-Listview) in a scrollview and then display the content.

Resources