Android java horizontal recyclerview in vertical match_parent not work - java

I followed the following tutorial: Here
.
Which allows you to create such a thing:
I modified the layout a little bit.
 
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#831067d2"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#384148"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<ImageView
android:id="#+id/iconApp"
android:layout_width="30dp"
android:layout_height="30dp" />
<TextView
android:id="#+id/titleApp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:text="Sample title"
android:textColor="#android:color/white" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal" />
</LinearLayout>
list_single_card.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:cardCornerRadius="5dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/previewImageWidget"
android:layout_width="150dp"
android:layout_height="150dp"
android:padding="5dp"
android:layout_gravity="center_horizontal" />
<TextView
android:id="#+id/nameWidget"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/previewImageWidget"
android:gravity="center"
android:padding="5dp"
android:text="Sample title"
android:textColor="#android:color/black"
android:textSize="18sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
The problem is the upper part where the "Section" is, does not take all the space it should take, its size is equal to the size of the content of the internal recyclerview the horizontal one.
Here:
I do not know if the problem is due to this:
 
MainActivity.java
RecyclerView my_recycler_view = (RecyclerView) findViewById(R.id.my_recycler_view);
my_recycler_view.setHasFixedSize(true);
RecyclerViewDataAdapter adapter = new RecyclerViewDataAdapter(this, allSampleData);
my_recycler_view.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
my_recycler_view.setAdapter(adapter);
or
RecyclerViewDataAdapter.java
SectionListDataAdapter itemListDataAdapter = new SectionListDataAdapter(mContext, singleSectionItems);
itemRowHolder.recycler_view_list.setHasFixedSize(true);
itemRowHolder.recycler_view_list.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
itemRowHolder.recycler_view_list.setAdapter(itemListDataAdapter);

Did you try to remove the second linear (in list_item.xml) layout's paddingLeft="10dp" and paddingTop="10dp" and then make change the layout_height="wrap_content" to layout_height="match_parent" for the first and second linear layout and make sure than #fillViewPort Is enabled for both of them

Modify your file list_item.xml to this:
<?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="wrap_content"
android:background="#831067d2">
<LinearLayout
android:id="#+id/horizontalBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="#384148"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:weightSum="10">
<TextView
android:id="#+id/titleApp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:text="Sample title"
android:textColor="#android:color/white"
android:layout_weight="9"/>
<ImageView
android:id="#+id/iconApp"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight="1"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal"
android:layout_below="#+id/horizontalBarLayout"/>
</RelativeLayout>

Related

Java Android Remove the outline of items in a recyclervciew

I am developing an activity that searches for users in my Firebase realtime DB and I am using a cradview as a layout to inflate:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="90dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:backgroundTint="#FFFFFF"
android:elevation="0dp"
android:layout_marginBottom="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<androidx.cardview.widget.CardView
android:id="#+id/crdProfileImage"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
app:cardBackgroundColor="#color/textC"
app:cardCornerRadius="30dp">
<ImageView
android:id="#+id/imgHolder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/user_default"
android:scaleType="centerCrop"/>
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/txtUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"
android:textColor="#color/black"
android:layout_marginTop="5dp"
android:fontFamily="sans-serif"
android:textStyle="bold"
android:layout_toEndOf="#+id/crdProfileImage"
android:layout_marginLeft="25dp"
android:textSize="25dp"/>
<TextView
android:id="#+id/txtBio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:layout_alignStart="#+id/txtUsername"
android:layout_marginTop="35dp"
android:text="Hi, this is my biography."/>
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
However, I noticed that when the recyclerview outputs the items, the items appear with an outline:
I thought it was the elevation, so I set it to 0, both on the recyclerview and on the layout in the cardview, but the result didn't change. Would anyone know how to solve?
EDIT:
I tried to remove the margin bottom but it still shows the elevation:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="90dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:backgroundTint="#FFFFFF"
card_view:cardElevation="0dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<androidx.cardview.widget.CardView
android:id="#+id/crdProfileImage"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
app:cardElevation="0dp"
app:cardBackgroundColor="#color/textC"
app:cardCornerRadius="30dp">
<ImageView
android:id="#+id/imgHolder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/user_default"
android:scaleType="centerCrop"/>
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/txtUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"
android:textColor="#color/black"
android:layout_marginTop="5dp"
android:fontFamily="sans-serif"
android:textStyle="bold"
android:layout_toEndOf="#+id/crdProfileImage"
android:layout_marginLeft="25dp"
android:textSize="25dp"/>
<TextView
android:id="#+id/txtBio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:layout_alignStart="#+id/txtUsername"
android:layout_marginTop="35dp"
android:text="Hi, this is my biography."/>
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
Use
card_view:cardElevation="0dp"
Instead of
android:elevation="0dp"
Add the following line of code to disable the outlineProvider:
android:outlineProvider="none"
in addition to the android:elevation being 0dp just remove the android:layout_marginBottom="20dp" from your <com.google.android.material.card.MaterialCardView /> and then add android:padding for your children view in it to make the spacing

Issue with listview scrollable

i don't know why my list view doesn't scroll completely.
I show you also single list view item.XML about adapter's xml where i put the item for every rows of my listview, so i hope that you can help me!
Thanks everybody!
I show you pic!
https://i.stack.imgur.com/8ub2W.png
this is .xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/a"
android:layout_marginLeft="5dp"
android:background="#color/white"
>
<ListView
android:id="#+id/listview"
android:layout_marginTop="0dp"
android:layout_width="fill_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
single_listview_item.XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
>
<CheckBox
android:id="#+id/chk_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" />
<ImageView
android:id="#+id/ivImage"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_toRightOf="#id/chk_box"
android:layout_toLeftOf="#id/ivImage"
android:orientation="vertical">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/chk_box"
android:textStyle="bold"
android:textColor="#000000"
android:text="This ia name"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/caratteristica"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/name"
android:layout_toRightOf="#id/chk_box"
android:textStyle="italic"
android:text="This is caratteristica"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/dist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="italic"
android:text="10"/>
<TextView
android:id="#+id/valuta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textSize="12sp"
android:textStyle="italic"
android:text="$"/>
</LinearLayout>
<Spinner
android:id="#+id/simpleSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:entries="#array/country_arrays"
android:visibility="visible"/>
<NumberPicker
android:id="#+id/np"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"/>
</LinearLayout>
</RelativeLayout>
In your adapter's xml , RelativeLayout tag ,write wrap_content replace of match_parent like below;
android:layout_height="wrap_content"
Change your single_listview_item.XML's RelativeLayout from android:layout_height="match_parent" to android:layout_height="wrap_content"
Change your ListView's height to wrap_content too

How to add spacing between each Item in list view

I just created a simple custom list view and I want to add spacing between each item in list View I already added vertical spacing attribute but there's no spacing yet this is my xml file for list view
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="abtech.waiteriano.com.waitrer.fragments.LVMenuFragment">
<!-- TODO: Update blank fragment layout -->
<ListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:verticalSpacing="20dp"
android:layout_height="fill_parent" >
</ListView>
</FrameLayout>
and this is listitem.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/menuRL"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:background="#drawable/listviewborder">
<ImageView
android:id="#+id/itemImage"
android:layout_width="65dp"
android:layout_height="fill_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
app:srcCompat="#drawable/icic" />
<TextView
android:id="#+id/menulistTV2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/itemImage"
android:text="TextView"
android:textSize="16dp"
android:textStyle="bold" />
<RelativeLayout
android:id="#+id/qtyID"
android:layout_width="75dp"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_toStartOf="#+id/minusBtn"
android:background="#drawable/qty_border">
<TextView
android:id="#+id/txtQTY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="0"
android:textSize="30dp" />
</RelativeLayout>
<Button
android:id="#+id/minusBtn"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:background="#drawable/minus_borders"
android:text="-"
android:textSize="40dp" />
</RelativeLayout>
</LinearLayout>
Just use:
android:divider="#android:color/transparent"
android:dividerHeight="20dp"
in ListView
<ListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:marigin_bottom="5dp";
android:verticalSpacing="20dp"
android:layout_height="fill_parent" >
</ListView>
Find the solution
In listitem add margin
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:orientation="vertical">
<TextView/>
<TextView/>
</LinearLayout>
For First and Last Item add margin in Listview
<Listview
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>

Android studio XML textview on an imageview

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<ImageView
android:layout_width="433dp"
android:layout_height="210dp"
android:layout_marginTop="25dp"
android:id="#+id/imageView"
android:scaleType="fitXY"
android:contentDescription="#string/image_description" />
<TextView
android:id="#+id/item_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="#string/list_number_placeholder"
android:textColor="#color/bar_separator_color"
android:layout_centerInParent="true"
android:textSize="50dp"
android:gravity="center"
android:layout_marginLeft="85dp"
/>
I have a question i cant get the text on my imageview, i think its something with the layers. Please help me..
im btw a beginner in Android studio XD
you are using LinearLayout which stacks your view one by one, either in horizontal direction or vertical direction (Orientation).
So use RelativeLayout instead if you want views overlapping.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<ImageView
android:layout_width="433dp"
android:layout_height="210dp"
android:layout_marginTop="25dp"
android:id="#+id/imageView"
android:scaleType="fitXY"
android:contentDescription="#string/image_description" />
<TextView
android:id="#+id/item_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="#string/list_number_placeholder"
android:textColor="#color/bar_separator_color"
android:layout_centerInParent="true"
android:textSize="50dp"
android:gravity="center"
android:layout_marginLeft="85dp"
/>
</RelativeLayout>
Change your Linear Layout to Relative layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<ImageView
android:layout_width="433dp"
android:layout_height="210dp"
android:layout_marginTop="25dp"
android:id="#+id/imageView"
android:scaleType="fitXY"
android:contentDescription="#string/image_description" />
<TextView
android:id="#+id/item_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="#string/list_number_placeholder"
android:textColor="#color/bar_separator_color"
android:layout_centerInParent="true"
android:textSize="50dp"
android:gravity="center"
android:layout_marginLeft="85dp"
/>
</RelativeLayout>
**Well You are better to use framelayout **. I hope this will help you
its not good way. better print something with java like:
LinearLayout lView = new LinearLayout(this);
myText = new TextView(this);
myText.setText("My Text");
lView.addView(myText);
setContentView(lView);
This works.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="433dp"
android:layout_height="210dp"
android:layout_marginTop="25dp"
android:id="#+id/imageView"
android:scaleType="fitXY"
android:contentDescription="hii" />
<TextView
android:id="#+id/item_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="yo"
android:textColor="#color/bg_login"
android:layout_centerInParent="true"
android:textSize="50dp"
android:gravity="center"
android:layout_marginLeft="85dp"
/>
</RelativeLayout>
</LinearLayout>
This code put the text in the middle of the image as you've requested for.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:id="#+id/nations"
android:background="#color/colorPrimary"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#color/colorPrimary"
android:layout_height="wrap_content">
<ImageView
android:src="#mipmap/ic_launcher"
android:layout_width="433dp"
android:layout_height="210dp"
android:layout_marginTop="25dp"
android:id="#+id/imageView"
android:scaleType="fitXY"
android:contentDescription="image" />
<TextView
android:id="#+id/item_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="#string/list_number_placeholder"
android:textColor="#color/bar_separator_color"
android:textSize="50dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/></RelativeLayout>
</LinearLayout>
Try this
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/picture"
android:scaleType="centerCrop" />
<TextView
android:id="#+id/text"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="My super text"
android:textColor="#android:color/white"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:textSize="48sp" />
<LinearLayout
android:id="#+id/controls"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#7f000000"
android:orientation="vertical"
android:layout_gravity="bottom"/>
</FrameLayout>

Android layout inconsistency

I have a layout that is being displayed in two different layouts. First one is being displayed in a LinearLayout and it behaves as expected:
However, when this layout is part of a listview, the textview is not centered:
Here's the layout:
<?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="130dp"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="horizontal"
android:padding="5dp">
<com.parse.ParseImageView
android:id="#+id/iv"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="fitCenter"/>
<TextView
android:id="#+id/tv_title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.5"
android:layout_marginLeft="10dp"
android:textAppearance="#android:style/TextAppearance.Holo.Medium"
android:ellipsize="end"
android:maxLines="3"
android:textStyle="bold"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:orientation="horizontal"
android:paddingLeft="10dp">
<View
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#color/blue"
android:layout_gravity="center"
/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/gray"
android:layout_margin="7dp"
/>
<TextView
android:id="#+id/tv_source"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textAppearance="#android:style/TextAppearance.Holo.Small"
android:gravity="center"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/gray"
android:layout_margin="7dp"
/>
<TextView
android:id="#+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="sans-serif-light"
android:textAppearance="#android:style/TextAppearance.Small"
android:gravity="center"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/gray"
android:layout_margin="7dp"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_fire"
android:layout_gravity="center"/>
<TextView
android:id="#+id/tv_viewCount"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="sans-serif-light"
android:textAppearance="#android:style/TextAppearance.Small"
android:gravity="center"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="5dp"/>
</LinearLayout>
<ImageView
android:id="#+id/pin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_pin"/>
<TextView
android:id="#+id/comment_tv"
android:layout_width="0dp"
android:layout_height="0dp"
android:textColor="#color/white"
android:layout_alignTop="#+id/pin"
android:layout_alignBottom="#+id/pin"
android:layout_alignLeft="#id/pin"
android:layout_alignRight="#+id/pin"
android:gravity="center"
android:layout_marginBottom="10dp"/>
</RelativeLayout>
The textView that I am referring to is at the bottom with id comment_tv
What am I doing wrong?
Thanks
Your pin+text inside a relative layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_gravity="center_vertical" >
<ImageView
android:id="#+id/pin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_pin"/>
<TextView
android:id="#+id/comment_tv"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="#id/pin"
android:gravity="center"
android:layout_marginTop="10dp" //set this higher if you need
android:layout_centerHorizontal="true" //if this text will be not in the center
//you can use the "layout_marginLeft" to put whatever you want
/>
</RelativeLayout>
This should but the text on the spot you want
I tried it with your image and this is my result with underlying code. Is this what you are looking for?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/sample"
android:gravity="center"
android:text="12"
android:textSize="18sp" />
</LinearLayout>
And heres a snapshot of this code:

Categories