I'm using a compound TextView inside a <RelativeLayout> with an image on top of the text via drawableTop. What I want, is to be able to add a vertical rule/border on the right side of the compounded TextView.
This is how the image looks like right now:
This is how I want it to look like:
This is how I'm making the compounded TextView
<TextView
android:id="#+id/searchRadiusText"
android:layout_width="70dp"
android:layout_height="match_parent"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:textColor="#android:color/white"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="100 km"
android:gravity="center_horizontal"
android:drawableTop="#drawable/ic_search_radius"
android:drawablePadding="15dp" />
The TextView and SeekBar are inside a RelativeLayout. Thank you for your help.
Solved it! Included a <view> after TextView and styled it to display a border on the right.
Here's how:
<TextView
android:id="#+id/searchRadiusText"
android:layout_width="70dp"
android:layout_height="match_parent"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:textColor="#android:color/white"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="100 km"
android:gravity="center_horizontal"
android:drawableTop="#drawable/ic_search_radius"
android:drawablePadding="15dp" />
<View
android:id="#+id/vertical_border"
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/searchRadiusText"
android:background="#color/btn_gray_light"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp" />
and then, I added the <SeekBar> with android:layout_toRightOf attribute with view's ID.
Related
I have four TextView in LinearLayout with orientation="horizontal". Below in image, I want my fourth TextView to vertically center with respect to other views, In simple words, I want to move my fourth TextView a little bit up so it looks like in the center. I tried to add layout:gravity and margins but its not working.
Here is the code:
<LinearLayout
android:id="#+id/tv_amenities"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_main_feature_LL"
android:layout_marginStart="10dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/rating_background"
android:drawableTop="#drawable/ic_food_and_restaurant"
android:padding="3dp"
android:text="Resturant"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#android:color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:background="#drawable/rating_background"
android:drawableTop="#drawable/ic_tv_black_24dp"
android:padding="3dp"
android:text="LCD Tv"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#android:color/white"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:background="#drawable/rating_background"
android:drawableTop="#drawable/ic_local_parking_black_24dp"
android:padding="3dp"
android:text="Parking"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#android:color/white"
/>
<TextView
android:id="#+id/tv_plus_amenities"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginBottom="20dp"
android:background="#drawable/round_background"
android:text="+15"
android:textColor="#android:color/white" />
</LinearLayout>
You could easily do that by adding android:layout_gravity="center_vertical" and removing your margin bottom.
<TextView
android:id="#+id/tv_plus_amenities"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_gravity="center_vertical"
android:background="#drawable/round_background"
android:text="+15"
android:textColor="#android:color/white" />
Add this prop to your #+id/tv_amenities LinearLayout
android:gravity="center_vertical"
Use android:layout_gravity="center_vertical" attribute in your TextView's
I checked your code inside a constraint layout and it's fine.
All I changed is in your last TextView:
android:layout_gravity="center"
Or
android:layout_gravity="center_vertical"
The layout_gravity=center looks the same as
layout_gravity=center_horizontal here because they are in a vertical
linear layout. You can't center vertically in this case, so
layout_gravity=center only centers horizontally.
This link can help you to fix your issue in LinearLayout or RelativeLayout.
You might find this link useful:What is the difference between gravity and layout_gravity in Android?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2"
android:background="#ffffff">
<TextView
android:id="#+id/sorttxt"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="0.995"
android:text="Sort"
android:textSize="17dp"
android:textColor="#000000"
android:background="#25a65b"
android:drawableLeft="#drawable/leftImagesort"
android:gravity="center"
/>
<View
android:layout_width="0dp"
android:layout_height="40dp"
android:background="#color/grey_5"
android:layout_weight="0.01" />
<TextView
android:id="#+id/filtertxt"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="0.995"
android:text="Sort"
android:textSize="17dp"
android:textColor="#000000"
android:background="#25a65b"
android:drawableLeft="#drawable/leftImagefilter"
android:gravity="center"
/>
I am using above code but wants to remove gap between image and text i have used android:drawableLeft to insert image in textview
right now i am getting output shown in image
Set attribute android:gravity="left" instead of android:gravity="center" in both TextView
If you are using drawable left for showing image and you want to remove gap between image and text then you need to use android:drawablePadding="-20dp". you need to give drawablePadding in minus.
You can use like :
android:drawableLeft="#mipmap/ic_launcher"
android:drawablePadding="-20dp"
set drawablePadding="0dp" and android:gravity="left|center"
I have these two TextViews in my content_main, I am a beginner and i can't figure out why are they overlapping in the center, I tried chanign everything and it still doesn't work.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="top"
android:text=""
android:id="#+id/nameTextView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="35sp"
android:textColor="#1a237e" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="bottom"
android:text=""
android:id="#+id/temperatureTextView"
android:layout_alignParentTop="false"
android:layout_centerHorizontal="true"
android:textSize="50sp"
android:textColor="#00bcd4" />
Try adding this code on the second TextView(#tempratureTextView):
layout_below="#+id/nameTextView"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:id="#+id/nameTextView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="35sp"
android:textColor="#1a237e" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:id="#+id/temperatureTextView"
android:layout_below="#+id/nameTextView"
android:layout_centerHorizontal="true"
android:textSize="50sp"
android:textColor="#00bcd4" />
</RelativeLayout>
The layout xml above will work.
Besides that, I noticed that you are trying to use android:gravity to position your TextView on top and bottom. This will not work because android:gravity only set the gravity of the content(the text) in your TextView. Use android:layout_gravity to set the TextView's gravity within the parent container.
layout_alignParentTop makes sure that your view stays at top,regardless of other views.Same thing about layout_alignParentBottom it makes view stick to bottom.
In your scenario you want these TextView one below other, So you have to specify android using, layout_below for the bottom element.
Anyway you have the answers as others has provided it,just making it clear about reason.
I have an ImageView and TextView inside a RelativeLayout to move them all around as a group that sticks together. It looks fine in the Graphical Layout inside Eclipse.
(The blue shows the outline for the RelativeLayout):
However when I run the app, the child views appear squished toghether or on top of each other. The ImageView doesn't even show anymore. I'm not sure why this occurs?
XML
<RelativeLayout
android:id="#+id/frameB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/squashcourt"
android:layout_alignLeft="#+id/squashcourt"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:clickable="true"
android:orientation="vertical" >
<TextView
android:id="#+id/tv_aboveB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="3dp"
android:clickable="true"
android:text="Robin"
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/Red"
android:textStyle="bold" />
<ImageView
android:id="#+id/btn_B"
android:layout_width="115dp"
android:layout_height="115dp"
android:layout_below="#+id/tv_aboveB"
android:layout_centerHorizontal="true"
android:layout_margin="3dp"
android:clickable="true"
android:scaleType="fitXY"
android:src="#drawable/b_left" />
</RelativeLayout>
I'm using a Samsung S4. Can anyone suggest something?
Thanks in advance!
You can Use simply TextView with bottom drawable .
<TextView
android:id="#+id/tv_aboveB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:text="Robin"
android:drawableBottom="#drawable/ic_launcher"
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ff0000"
android:textStyle="bold" />
Now you can move the TextView any where on the screen.
I want to create layout like at picture but i don't have clue at all how to make like that..
Does anyone can give me a clue or alternative how to do that ?
Split it like this.
Imageview and first textview in a linearlayout Horizontal.
and then this linearlayout Horizontal and second textview in a linear layout vertical.
One way to do this could be to lay the TextView and then overlay the ImageView on it. I think a RelativeLayout with the TextView defined first and followed by the ImageView might do the trick. You can toggle the visibility of the ImageView but would need to ensure that any text written to the TextView is written after taking into account width of the ImageView so as to not obscure any text.
You can try adding two textviews in a relative layout and in addition to that an imageview.
This might help you to get started.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/item_generator"
android:background="#FF000000">
<TextView
android:id="#+id/item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:textColor="#FFF"
android:textSize="18sp" />
<TextView
android:id="#+id/item_title_val"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:layout_marginTop="16dp"
android:textColor="#color/blue"
android:textSize="16sp" />
<TextView
android:id="#+id/item_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/item_title"
android:layout_below="#+id/item_title"
android:textColor="#888"
android:textSize="14sp" />
<ImageView
android:id="#+id/item_right_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:layout_marginRight="40dp"
android:padding="0dp"
android:contentDescription="#string/hello_world" />
</RelativeLayout>