how to adjust spinner text like Google translate? - java

I want to adjust my spinner like Google android translate
I want to adjust my left spinner text like the right image, below the given code is my left side spinner
<Spinner
android:id="#+id/idFromSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="end"
android:layout_marginStart="-3dp"
android:paddingEnd="30dp"
android:paddingStart="15dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
Please help me in this project actually my task is to make a spinner like Google translate
I want to make left spinner left side and right spinner right side margin fix it should not change on increasing or decreasing text length

You can add in android:layout_marginRight="10dp". Just adjust " 10dp" time and time again, good luck on that spinner!
Edit:
The solution is a good use if the left-side spinner is android:layout_toLeftOf="#+id/middle_switcher but if not. You could just use any other Layouts like the GridLayout...

Related

Is it possible to make a TextView marquee stop and reverse when the whole text has been shown?

I have a TextView that represents the title of the current fragment and is located in the toolbar. When the user uses a big font size, the title sometimes becomes too long to be displayed completely. Hence I want to have it scroll to the right until the whole text has been shown, then stop for two seconds and then scroll back to the left where it stops as well. This should be repeated forever.
I have tried using marquee to accomplish this (see below), but there doesn't seem to be any option to make marquee stop scrolling, let alone dynamically reverse it. If there are any alternatives to marquee that have this option, I'd be happy to use them as well.
Currently the TextView looks like this:
<TextView
android:id="#+id/title_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"/>
there is no such option, you have to end with custom solution. some sample with custom initialization can be found here (speeds up marquee, you have to modify code)

Android Studio Layout Auto Alignment

I am new to Android Studio, and no matter what I do whenever I add something such as a textview or button to it, I cannot make it the size I want it to. It always auto aligns itself to the sides or top. When I want to make a square it doesn't allow me to do it. It never allows me to put my button or textview where I want it to. How do I make it so I can place my stuff anywhere I want and whatever size I choose it to be?
You are probably using linear layout,You can use relative layout instead for start, although if you want to put a lot of buttons its getting harder to work with relative layout and linear layout is more organized go to you'r xml and there edit the in the first line where it says <LinearLayout... to <RelativeLayout> and don't forget to do the same at closing,I recommend you to watch a video on youtube on how to work with linear layouts.
In RelativeLayout, it enable the attributes like alignParentRight="true/false" for exact right position and so on...
layout_below="#id/tool/viewID_below_you_want_to_put" and same for other side
so you can use it
For Example,
<RelativeLayout
...>
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_toRightOf="#id/txt1"
android:alignParentRight="true"
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
which will make your textview in left and then button in right of textview
If you want to set it in center tou can set gravity="center | center_vertical | center_horizontal"
also you can set size as you want in width or height like
android:layout_width="50dp"

Making 2 dynamic TextViews not overlap

I have been working on an app that shows statuses about a server. I have a CardView for each server, with a RelativeView inside. On the left is an image, aligned to the cards left. In the middle, I have a TextView, aligned to the image right. On the right, I have a TextView, aligned to the right of the card.
Basically, my issue is, without using a LinearLayout, how can I make it so the middle TextView does not overlap the right TextView, preferably in the layout's XML? The text in both views is dynamically long, making a LinearLayout not very preferable.
Here is a diagram of the Layout to help you picture what I'm talking about. Sorry for the external link, it was getting reformatted in the post.
1.Aline middle TextView to centerHorizontal of parent, give fixed width , margin left and right to it. Mention that it is right of another TextView by using layout_toLeftOf.
2.Also aligh right hand side TextView to right by using alignRightToParent = true. Then give left margin to it.
I tried by using below xml code:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="#+id/sun"
android:background="#004700" >
<TextView
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginRight="20dp"
android:layout_toLeftOf="#+id/sun12"
android:singleLine="false"
android:text="abcdgsss ssssssssssssssss ssssssss sssssssssssssssssssssss"
android:textColor="#fff"
android:textSize="16sp" />
<TextView
android :id="#+id/sun12"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:text="abcdgsss ssssssssssssssss ssssssss sssssssssssssssssssssss"
android:textColor="#fff"
android:textSize="16sp" >
</TextView>
</RelativeLayout>
I figured out how to do it programatically. Simply, you want to subtract the widths and padding of the surrounding views from the size of the container view, and set the leftover value to the text view's width. Here is an example:
int view_length = personViewHolder.container.getWidth() - personViewHolder.container.getPaddingStart() - personViewHolder.container.getPaddingEnd();
view_length = view_length - personViewHolder.object_to_left.getWidth() - personViewHolder.object_to_left.getPaddingStart() -personViewHolder.object_to_left.getPaddingEnd();
view_length = view_length - personViewHolder.object_to_right.getWidth() - personViewHolder.object_to_right.getPaddingStart() - personViewHolder.object_to_right.getPaddingEnd();
personViewHolder.view_to_set_width.getLayoutParams().width = view_length;
personViewHolder.view_to_set_width.invalidate();
You can place the views in a RelativeLayout (if they are not already in one), then and use the ToStartOf or ToEndOf attributes to align one of them to the start or end of the other. You could also use ToLeftOf or ToRightOf, but this is not recommended because in some locales you want the user to read from right to left instead of left to right. This will ensure that the two views never overlap (assuming you haven't placed negative margins on either of the views). This can be extended to as many views as you want, as long as you correctly configure their alignment attributes.

Android custom ListView item

I've set up a ListView and assigned a custom layout to make the ListView items better looking. However, I'm looking for a way to add a button that would appear with each element in it's top right corner, like Youtube's videos: they all have that little options button with things like add to, share, etc. The problem is that you cant put a widget inside of a widget, at least I don't know a way to do it. The custom layout contains a TextView which gives the ListView items the looks. Can someone suggest a way on how should I approach this?
Use FrameLayout for your custom ListView items. like this:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/tvText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
<Button android:id="#+id/button"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_gravity="top|right"
/>
</FrameLayout>
NB - when widgets overlaps in layout, last written widget will be topmost.
Here is a link where you will find what you want.
It shows you how to add button in list view.
You will need to change some XML code and adjust the onClickListeners but it's similar to what you are looking for.

How to integrate spinner with no cement background in android

Need to remove the spinner background color but want to display the rectangle drop down mark...can any one please help me..
I used a 9-patch picture to change spinner background. How about this?
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/spinner_bg"/>
spinner_bg:

Categories