Android Scrollview doesn't wrap child - java

Here's the Layout xml file:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:scrollbars = "vertical">
<LinearLayout
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="factory.Settings"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblShopID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ShopId"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/txtShopID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblShopname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/lblShopID"
android:layout_marginTop="36dp"
android:text="#string/ShopName"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinShopName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/lblShopname"
android:layout_toRightOf="#+id/lblShopname" />
</LinearLayout>
<Button
android:id="#+id/btnSaveChanges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/spinShopName"
android:layout_marginTop="22dp"
android:onClick="saveData"
android:text="Save Changes" />
<TextView
android:id="#+id/txtChangePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:text="#string/ChangePassword"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginTop="30px" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30px">
<TextView
android:id="#+id/lblOldPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/OldPassword"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/txtOldPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblNewPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/NewPassword"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/txtNewPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblRetypePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/RetypePassword"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/txtRetypePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<Button
android:id="#+id/btnChangePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="changePassword"
android:text="Change Password" />
<ListView
android:id="#+id/lstUsers"
android:layout_width="340dp"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
And Here's the expecting output:
The expected output is : I have some items in lstUsers and there wouldn't be enough space for displaying all the users, so I would like to add a scrollview to the Layout to let users scroll down.
But the problem is: the scrollview doesn't wrap any controls at all, the outcome is:
As you can see, the scrollview is unable to wrap the lstUser
Is there anything wrong with the layout file?

I don't think you are allowed to put a listview in a scrollview. Listview implements its own scroller so it doesn't like being in a scrollview. Take a look at this link
How can I put a ListView into a ScrollView without it collapsing?

Scrollview and Listview do not work well with each other.
What I would suggest u is to make 'lstUsers' Listview the main content of the layout file.
Create a separate layout file with the views that are above the listview.
Then inflate this layout file and add it as a header view to the listview.

Related

Edittext Can not be editable due to property descendantFocusability="blocksDescendants" in My Recyclerview

I am facing some problem my edittext is not editable due to descendantFocusability="blocksDescendants" in Recyclerview.There is one Activity that have Recyclerview. if i am not use this descendantFocusability then my list loses its focus. Can anybody help me to solve this issue????? How to make Edittext editable. i was tried all solution like focusableintouchmode="true" and focusabale="false" etc.
Thanks in Advance.
**MyActivity.class**
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:andandroid="http://schemas.android.com/tools"
android:descendantFocusability="blocksDescendants"
android:background="#drawable/ic_bg">
<android.support.v7.widget.RecyclerView
android:id="#+id/listQuestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:orientation="vertical"
android:scrollbars="none" />
</RelativeLayout>
raw.xml
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:hedgehog="http://schemas.android.com/tools"
android:id="#+id/rawSubQuestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/ic_black_left_right"
android:minHeight="#dimen/_70sdp">
<RelativeLayout
android:id="#+id/rlMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/_5sdp"
android:paddingLeft="#dimen/_35sdp"
android:paddingRight="#dimen/_35sdp"
android:paddingTop="#dimen/_5sdp">
<!--Name-->
<TextView
android:id="#+id/txtName"
style="#style/commonTextStyle"
android:text="Name" />
<!--Description-->
<TextView
android:id="#+id/txtDescription"
style="#style/commonTextStyle"
android:layout_below="#+id/txtName"
android:gravity="top"
android:maxLines="3"
android:minLines="2"
android:singleLine="false"
android:text="Description"
android:textSize="#dimen/_10sdp" />
<LinearLayout
android:id="#+id/rlType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txtDescription"
android:layout_marginTop="#dimen/_2sdp"
android:orientation="vertical"
android:visibility="visible">
<RatingBar
android:id="#+id/ratingBar"
style="#style/RatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:background="#null"
android:isIndicator="false"
android:numStars="5"
android:stepSize="1.0"
android:visibility="visible" />
<LinearLayout
android:id="#+id/circleRatingLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:visibility="visible">
<com.whinc.widget.ratingbar.RatingBar
android:id="#+id/ratingBarCircle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:rb_click_rating="true"
app:rb_count="3"
app:rb_empty="#drawable/r_circle_white"
app:rb_fill="#drawable/r_circle_yellow"
app:rb_max_count="10"
app:rb_space="10dp"
app:rb_touch_rating="true" />
<TextView
android:id="#+id/CircleRatingTV"
style="#style/commonTextStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:text="1" />
</LinearLayout>
<RelativeLayout
android:id="#+id/rlSeekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:visibility="visible">
<SeekBar
android:id="#+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:max="10"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:progress="5"
android:thumb="#drawable/seekbar_thumb_drawable"
android:thumbOffset="0dp" />
<TextView
android:id="#+id/txtSeekBarCount"
style="#style/commonTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center"
android:minWidth="#dimen/_40sdp"
android:text="10"
android:textSize="#dimen/_12sdp" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<!--Note-->
<EditText
android:id="#+id/edtNote"
style="#style/editTextWhiteGray"
android:layout_centerVertical="true"
android:hint="#string/Note"
android:layout_below="#id/rlMain"
android:inputType="textMultiLine"
android:visibility="gone" />
Your EditText is outside of your root ViewGroup (RelativeLayout):
</RelativeLayout>
<!--Note-->
<EditText
android:id="#+id/edtNote"
style="#style/editTextWhiteGray"
android:layout_centerVertical="true"
android:hint="#string/Note"
android:visibility="gone"
/>
Include that EditText inside of your RelativeLayout. Also you should add android:inputType look here for more info. Add LayoutParams to all of your views where it's missing, why it is required described here. And recheck all your logic concerning EditText widget in your code.

Keyboard pushing edittext content when clicking

Keyboard pushing content of edittext up when I start writing something , already add android:windowSoftInputMode="adjustResize" in AndroidManifest. Please provide solution for this issue.
Here is my code.
<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="com.example.mouad.fixmyphone.fragment.SendUsFragment"
android:background="#ffff">
<!-- TODO: Update blank fragment layout -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_below="#id/idtitle"
android:background="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E-mail :"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#1A237E"
android:layout_marginTop="90sp"
android:id="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:text="SEND"
android:textStyle="bold"
android:layout_width="130sp"
android:layout_height="wrap_content"
android:id="#+id/sendbtn"
android:textColor="#ffffff"
android:background="#drawable/roundshapebtn"
android:layout_marginTop="17dp"
android:layout_below="#+id/msgtext"
android:layout_centerHorizontal="true" />
<EditText
android:background="#drawable/rounded_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Your Problem in Short"
android:textStyle="bold"
android:id="#+id/msgtext"
android:maxLength="80"
android:maxLines="2"
android:inputType="textMultiLine"
android:layout_below="#+id/textmsgview"
android:layout_alignParentLeft="true"
android:drawableLeft="#drawable/ic_pb"
android:layout_alignParentStart="true"
android:drawablePadding="20dp"
android:paddingLeft="1dp"
android:paddingRight="12dp"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:layout_marginTop="17dp"/>
<EditText
android:background="#drawable/rounded_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Your E-mail . . ."
android:textStyle="bold"
android:id="#+id/emailtext"
android:inputType="textEmailAddress"
android:drawableLeft="#drawable/ic_email"
android:drawablePadding="20dp"
android:paddingLeft="1dp"
android:paddingRight="12dp"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="17dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tell us your problem :"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#1A237E"
android:layout_marginTop="20dp"
android:id="#+id/textmsgview"
android:layout_below="#+id/emailtext"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp" />
</RelativeLayout>
it seems like you use adjust_resize for the keyboard, the view will be "resized" to fit your view(i mean layout)
if you dont want any resize, change to adjustPan
FYR Difference between adjustResize and adjustPan in android?
Problem solved with ScrollView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Content here -->
</LinearLayout>
</ScrollView>
</LinearLayout>

How to add text above it?

I'm making a layout:
Here is a 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="wrap_content"
android:background="#373c5c"
android:gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout android:id="#+id/list_offer_item_container"
android:layout_marginTop="15dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/shape"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:id="#+id/imgcreditcompany"
android:layout_width="36dp"
android:layout_marginRight="4dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
android:contentDescription="#string/app_name"
android:layout_height="36dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="start"
android:orientation="vertical" >
<TextView
android:id="#+id/txtname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="1dp"
android:textColor="#48899f"
android:textSize="#dimen/textsizeearncredit_title"
android:text="Name"
android:textAllCaps="false"
android:textStyle="normal|bold" />
<TextView
android:id="#+id/txtdesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="1dp"
android:maxLines="1"
android:textColor="#80869c"
android:textSize="#dimen/textsizeearncredit_desc"
android:text="This is a description of the offer and this is just a demo to show off 3 lines stacking correctly on top of each other"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="20dp"
android:gravity="end"
android:layout_gravity="center_vertical">
<TextView android:id="#+id/list_offer_badge_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/list_offer_item_container"
android:textColor="#color/md_amber_700"
android:textSize="12sp"
android:visibility="gone"
android:text=""/>
</LinearLayout>
<ImageView
android:id="#+id/nextArrow"
android:layout_alignParentRight="true"
android:tint="#color/md_grey_300"
android:rotation="180"
android:layout_width="32dp"
android:visibility="gone"
android:layout_marginRight="16dp"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_height="32dp"
android:contentDescription="#string/app_name"
android:padding="#dimen/two" />
</LinearLayout>
</RelativeLayout>
How to add an text above the 'button style' linear layout?
I want for example "Hello dear user! Check it below".
Where put textview, where add more layout or whatever?
It is very simple!
You have to add TextView, with id (text, for example) and, in your LinearLayout you need to add line android:layout_below="#+id/text". Optional, you can specify attribute android:layout_alignParentTop="true" in TextView.
Just use code below:
<?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="#373c5c"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/text"
android:text="Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
/>
<LinearLayout android:id="#+id/list_offer_item_container"
android:layout_below="#+id/text"
android:layout_marginTop="15dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/shape"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:id="#+id/imgcreditcompany"
android:layout_width="36dp"
android:layout_marginRight="4dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
android:contentDescription="#string/app_name"
android:layout_height="36dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="start"
android:orientation="vertical" >
<TextView
android:id="#+id/txtname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="1dp"
android:textColor="#48899f"
android:textSize="#dimen/textsizeearncredit_title"
android:text="Name"
android:textAllCaps="false"
android:textStyle="normal|bold" />
<TextView
android:id="#+id/txtdesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="1dp"
android:maxLines="1"
android:textColor="#80869c"
android:textSize="#dimen/textsizeearncredit_desc"
android:text="This is a description of the offer and this is just a demo to show off 3 lines stacking correctly on top of each other"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="20dp"
android:gravity="end"
android:layout_gravity="center_vertical">
<TextView android:id="#+id/list_offer_badge_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/list_offer_item_container"
android:textColor="#color/md_amber_700"
android:textSize="12sp"
android:visibility="gone"
android:text=""/>
</LinearLayout>
<ImageView
android:id="#+id/nextArrow"
android:layout_alignParentRight="true"
android:tint="#color/md_grey_300"
android:rotation="180"
android:layout_width="32dp"
android:visibility="gone"
android:layout_marginRight="16dp"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_height="32dp"
android:contentDescription="#string/app_name"
android:padding="#dimen/two" />
</LinearLayout>
</RelativeLayout>
Above
<LinearLayout android:id="#+id/list_offer_item_container"
put your TextView or whatever you want. So something like
<TextView android:id="#+id/myTV"
// other attributes />
Then in
<LinearLayout android:id="#+id/list_offer_item_container"
add android:layout_below="#id/myTV"
By default, RelativeLayout puts it's elements at the top-left until you specify otherwise. So adding this will put your LinearLayout below the TextView.
I think the confusion is on how RelativeLayout and LinearLayout work. You have orientation in your RelativeLayout which does nothing. RelativeLayout puts it's elements in the order you tell it by the attributes such as layout_below and layout_above. LinearLayout, however, adds them in the order in which they show in the xml file which is why orientation matters in LinearLayout but not RelativeLayout.
You'll want to look at RelativeLayout.LayoutParams and other parts of the documentation to better understand how the layouts work and which is best in your specific cases.

In a relative layout how can I make the last element adjust to the increase of data in the preceding elements?

I have a layout as follows. The problem I have is that if the TextView of friend_name is very long it “pushes” down the rest and they overlap/cover last ViewStub of friend_last_msg
How can I make the last ViewStub to also “adjust” on this “lowering of the other widgets?
Or else how could I make that last view stub to be inside the LinearLayout and displayed to the left side and down?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
>
<ImageView
android:id="#+id/friend_img”
android:layout_width="#dimen/friend_big”
android:layout_height="#dimen/friend_big”
android:layout_alignParentLeft="true"
android:scaleType="centerCrop"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="8dp"
android:layout_toRightOf="#+id/friend_img"
>
<TextView
android:id="#+id/friend_name”
android:layout_toRightOf="#id/friend_img"
android:layout_marginBottom="#dimen/layout_small_padding"
android:includeFontPadding="false"
android:paddingBottom="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:ellipsize="end"
android:gravity="top"
/>
<ViewStub
android:id="#+id/friend_sign”
android:inflatedId="#+id/friend_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="#layout/friend_sign_layout”/>
<TextView
android:id="#+id/friend_contact”
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
android:padding="5dp"
/>
</LinearLayout>
<ViewStub
android:id="#+id/friend_last_msg”
android:inflatedId="#+id/friend_last_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout="#layout/friend_last_msg"/>
</RelativeLayout>
First of all enter the closing commas right like this then enter the android:layout_height and android:layout_width values according to your needs.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
>
<ImageView
android:id="#+id/friend_img[**"**]
android:layout_width="#dimen/friend_big[**"**]
android:layout_height="#dimen/friend_big"
android:layout_alignParentLeft="true"
android:scaleType="centerCrop"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="8dp"
android:layout_toRightOf="#+id/friend_img"
>
<TextView
android:id="#+id/friend_name[**"**]
android:layout_toRightOf="#id/friend_img"
android:layout_marginBottom="#dimen/layout_small_padding"
android:includeFontPadding="false"
android:paddingBottom="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:ellipsize="end"
android:gravity="top"
/>
<ViewStub
android:id="#+id/friend_sign"
android:inflatedId="#+id/friend_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="#layout/friend_sign_layout"/>
<TextView
android:id="#+id/friend_contact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
android:padding="5dp"
/>
</LinearLayout>
<ViewStub
android:id="#+id/friend_last_msg"
android:inflatedId="#+id/friend_last_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout="#layout/friend_last_msg"/>
You can to use this way:
Add an id -> #+id/container to parent
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_toRightOf="#+id/friend_img"
android:orientation="vertical">
For your stub layout just change to this:
<ViewStub
android:id="#+id/friend_last_msg"
android:inflatedId="#+id/friend_last_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/container"
android:layout_toRightOf="#+id/friend_img"
android:layout_alignParentRight="true"
android:layout="#layout/friend_last_msg"/>

Centering my linear layout in android

I'm trying to achieve this positioning:
Where I have two rows of EditText and TextView next to each other.
The version textview is anchored to the bottom of the screen, but takes up the entire width and the text is centered.
My current layout file is this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:orientation="vertical"
android:gravity="center_vertical"
tools:context="com.example.mp.MainActivity$PlaceholderFragment" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edittext1"
android:layout_width="250dip"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NEW"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edittext2"
android:layout_width="250dip"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NEW"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dip"
android:gravity="bottom">
<TextView
android:id="#+id/textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Version 1.0"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt" />
</RelativeLayout>
</LinearLayout>
But the two rows of EditText and TextView are positioned past the middle of the screen and the Version textview is immediately below the two rows of EditText and TextView instead of anchored at the bottom.
I would recommend using a RelativeLayout for the root layout and use the property android:layout_alignParentBottom="true" for the "version". Then wrap the other Views in a LinearLayout. Something like
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
<EditText
android:id="#+id/edittext1"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textview1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="NEW"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/edittext2"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textview2"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:text="NEW"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Version 1.0"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
I haven't had a chance to really test it but this should get you pretty close. I wrapped the two sets of Views in the center in a LinearLayout then gave each their own LinearLayout so they can make use of weight (which you can adjust to your needs). The parent LinearLayout is centered vertical so that those 4 Views will be centered the way I believe you want.
<LinearLayout 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:orientation="vertical"
android:gravity="center">//hope this will work for you
<LinearLayout
android:id="#+id/alltextfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"`enter code here`
android:orientation="horizontal" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="EditText" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New" />
</LinearLayout>
<LinearLayout
android:id="#+id/alltextfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="EditText" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New" />
</LinearLayout>

Categories