I'm trying to set my ImageView and LinearLayout to have half of the screen each. This works fine on tablets, but on smaller screens the image takes up the entire screen (thus, not actually working).
The way I see it is, I have set a layout_weight="1" on both the ImageView and LinearLayout and the layout_width="0dp" on both also. This SHOULD work, as I have researched a lot into this.
My Code:
<?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"
android:background="#color/button_text_white">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#drawable/image"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:padding="20dp"
android:orientation="vertical"
android:gravity="bottom">
<TextView
android:id="#+id/text_view_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:gravity="center"
android:textSize="24dp"
android:textColor="#color/button_text_white"
android:visibility="invisible"/>
<TextView
android:id="#+id/text_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sign_up_in_username_text"
android:textColor="#color/color"/>
<EditText
android:id="#+id/edit_text_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:inputType="text"
android:textColor="#color/color"
android:hint="#string/sign_up_in_username_hint"/>
<TextView
android:id="#+id/text_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sign_up_in_email_text"
android:textColor="#color/color"/>
<EditText
android:id="#+id/edit_text_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:inputType="textEmailAddress"
android:textColor="#color/color"
android:hint="#string/sign_up_in_email_hint"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sign_up_in_password_text"
android:textColor="#color/color"/>
<EditText
android:id="#+id/edit_text_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:inputType="textPassword"
android:textColor="#color/color"
android:hint="#string/sign_up_in_password_hint"/>
<TextView
android:id="#+id/text_view_forgotten_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:gravity="right"
android:text="#string/forgotten_password_text"
android:textColor="#color/color"/>
<Button
android:id="#+id/button_sign_up_in"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textColor="#color/color"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Thanks, appreciate any help!
I would say your problem is with your LinearLayout's height being set to match_parent inside of a ScrollView.
As you know, a ScrollView expands to fit its contents - now if you tell its contents to expand as big as its parent (match_parent), then you have a paradox.
Try setting the child of your ScrollView's height to wrap_content instead of match_parent.
There is no use for your ScrollView & it's parent RelativeLayout. Cut down your layout as below.
<LinearLayout>
<ImageView w="1"/>
<ScrollView w="1">
<LinearLayout>
....
</LinearLayout>
</ScrollView>
</LinearLayout>
.
<?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"
android:background="#color/button_text_white">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#drawable/image"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
android:orientation="vertical"
android:gravity="bottom">
<TextView
android:id="#+id/text_view_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:gravity="center"
android:textSize="24dp"
android:textColor="#color/button_text_white"
android:visibility="invisible"/>
<TextView
android:id="#+id/text_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sign_up_in_username_text"
android:textColor="#color/color"/>
<EditText
android:id="#+id/edit_text_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:inputType="text"
android:textColor="#color/color"
android:hint="#string/sign_up_in_username_hint"/>
<TextView
android:id="#+id/text_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sign_up_in_email_text"
android:textColor="#color/color"/>
<EditText
android:id="#+id/edit_text_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:inputType="textEmailAddress"
android:textColor="#color/color"
android:hint="#string/sign_up_in_email_hint"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sign_up_in_password_text"
android:textColor="#color/color"/>
<EditText
android:id="#+id/edit_text_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:inputType="textPassword"
android:textColor="#color/color"
android:hint="#string/sign_up_in_password_hint"/>
<TextView
android:id="#+id/text_view_forgotten_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:gravity="right"
android:text="#string/forgotten_password_text"
android:textColor="#color/color"/>
<Button
android:id="#+id/button_sign_up_in"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textColor="#color/color"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Related
Every layouts in project has include layout. I have designed well in iclude layout. But in main layout of include layout don't show same view. for example the buttons move to the right of screen. I did different screen designs for small, normal, large and xlarge. But that didn't solve problem.
activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="#+id/loginlayout"
android:layout_height="match_parent"
android:background="#drawable/login_arkaplan"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100"
android:layout_marginRight="30dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:layout_weight="90"
android:orientation="vertical"
>
<include layout="#layout/login_inner_part" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:orientation="horizontal"
android:layout_weight="10"
android:weightSum="2"
android:layout_gravity="center"
>
<TextView
android:id="#+id/textViewForgetPass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lostpass"
android:textColor="#color/colorOrange"
android:textStyle="bold" />
<TextView
android:id="#+id/textViewRegister"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="#string/register"
android:textColor="#color/colorWhite"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
activity_login_inner_part.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"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="20"
android:gravity="center"
android:background="#color/colorWhite"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="10"
android:gravity="center"
android:weightSum="3">
<ImageView
android:id="#+id/login_logo"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
app:srcCompat="#drawable/login_logo"
android:layout_gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:orientation="vertical">
<EditText
android:id="#+id/login_username"
android:layout_width="185dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:backgroundTint="#color/colorGrey"
android:ems="10"
android:hint="Eposta"
android:inputType="textPersonName"
tools:layout_editor_absoluteX="84dp"
tools:layout_editor_absoluteY="267dp" />
<EditText
android:id="#+id/login_userpass"
android:layout_width="185dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:backgroundTint="#color/colorGrey"
android:ems="10"
android:hint="#string/password"
android:inputType="textPassword"
tools:layout_editor_absoluteX="84dp"
tools:layout_editor_absoluteY="341dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/btn_login"
style="?android:attr/buttonStyleSmall"
android:layout_width="185dp"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="20dp"
android:background="#color/colorPrimary"
android:clickable="true"
android:focusable="true"
android:text="GÖNDER"
android:textColor="#android:color/white" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I don't know why this button move right of screen. I am doing this include layouts first time and I don't know reason of it. I can't solve it. Please help me.
Possible solution would be to use RelativeLayout to center the button with reference to it's parent instead of giving it a fixed left margin.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn_login"
style="?android:attr/buttonStyleSmall"
android:layout_width="185dp"
android:layout_height="wrap_content"
<!-- IMPORTANT -->
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="#color/colorPrimary"
android:clickable="true"
android:focusable="true"
android:text="GÖNDER"
android:textColor="#android:color/white" />
</RelativeLayout >
So i have been working on my android project and the layout has gotten me and I cannot figure out what is the best to do something like this.
Currently my XML looks like this.
What i am trying to do is have 7 columns with one row that is filled with textviews. I was looking at Grid views but it seems like the entire point of the grid is to scroll with more than one row. How do I achieve this layout?
<android.support.constraint.ConstraintLayout
android:id="#+id/ConstraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/foodmenuexample"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textView9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textView8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textView11"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="123456789123456789123456789123456789123456789123456789123456789" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
<TextView
android:id="#+id/textView12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
The answer is... it depends. For simplicity, you can use a GridLayout, which if you have all your data within the view, this would work well.
However if you want the data to load from a database, or if there is an indeterminate amount of columns, then a gridview is your best bet inside a horizontal scrollview. You can just set the number of rows to 1, and the number of columns programmatically.
Example of that:
GridView gridView = (GridView) findViewById(R.id.gridview);
gridView.setNumColumns(numOfColumns);
Gridviews are more complicated because you will have to use an adapter, which you can learn about here:
https://developer.android.com/guide/topics/ui/layout/gridview.html
However, if you are looking for static simplicity, here is what you could do:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent">
<GridLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:rowCount="1"
android:columnCount="7">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Lots of text on this one" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Some text on this one" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Textview3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Textview4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Textview5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Textview6" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Textview7" />
</GridLayout>
</HorizontalScrollView>
</android.support.constraint.ConstraintLayout>
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
I want to implement the following layout:
I did it as follows:
<?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:layout_marginTop="10dp"
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginRight="20dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LABEL"
android:textSize="14sp"
android:layout_marginBottom="5dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:padding="10dp"
android:text="Text Box 1"
android:textSize="14sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LABEL 2"
android:layout_marginBottom="5dp"
android:textSize="14sp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="BLA-1"
android:background="#color/white"
android:textSize="14sp"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center|bottom"
android:text="and"
android:textSize="14sp"
/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="BLA-2"
android:background="#color/white"
android:textSize="14sp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Basically I used LinearLayouts and gravity.
It works but it seems kind of complex and I noticed that when I increase the margins left and right of the and text the texts BLA-1 and BLA-2 get cut off.
Is there a better way for this?
I think I can not use a relative layout as I would not be able to have the views take these sizes across the screen, right?
UPDATE:
Also with my approach any kind of padding in the TextViews cuts off the text
This looks the same as on screenshot (just customize colors)
<?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="horizontal"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LABEL" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFF"
android:hint="Text Box 1"
android:padding="4dp"
android:textColorHint="#757575" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LABEL2" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFF"
android:hint="BLA-1"
android:padding="4dp"
android:textColorHint="#757575" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:text="and" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFF"
android:hint="BLA-2"
android:padding="4dp"
android:textColorHint="#757575" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I think LinearLayout is a good choise even though it is complex if you want to keep the weights.
You should change all your TextViews to wrap_content so they won't get cut off.
If you still want to avoid spaces you can wrap each TextView with a LinearLayout or FrameLayout like this:
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LABEL2" />
</LinearLayout>
Here you can get it using Linear Layout. Have a look at below xml layout exactly what you are looking for.
<?xml version="1.0" encoding="utf-8"?>
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="3"
tools:ignore="DisableBaselineAlignment">
<LinearLayout
android:id="#+id/llOne"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="LABEL"
android:textSize="14sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:hint="textbox1"
android:padding="10dp"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/llTwo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="LABEL"
android:textSize="14sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:hint="BLA1"
android:padding="10dp"
android:textSize="14sp" />
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="0.3"
android:text="and"
android:textSize="14sp" />
<LinearLayout
android:id="#+id/llThree"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_weight="0.6"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:hint="BLA2"
android:padding="10dp"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
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: