ViewSwitcher with EditText leaves extra padding - android-layout

I'm using a ViewSwitcher to allow switching from a TextView to an EditText element. What I've noticed is that the EditText element generates extra padding at the bottom of the view (i.e. if I remove the EditText everything looks as expected, but adding it, even when visibility is set to gone, generates extra space at the bottom). What's causing this and how should it be resolved?
<ViewSwitcher
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/IngredientsLineSwitcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/IngredientsLineText"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:paddingBottom="0dip"
android:paddingLeft="10dip"
android:paddingTop="0dip"
android:text=""
android:textColor="#color/black"
android:textSize="#dimen/recipe_label_font_size" />
<EditText
android:id="#+id/IngredientsLineEdit"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:paddingBottom="0dip"
android:paddingLeft="10dip"
android:paddingTop="0dip"
android:text=""
android:visibility="gone"
android:textColor="#color/black"
android:textSize="#dimen/recipe_label_font_size" />
</ViewSwitcher>

You should put a RelativeLayout around the TextView or EditText to control their positioning.

-----
android:layout_height="match_parent" >
mlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/IngredientsLineSwitcher"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/IngredientsLineText"
android:layout_height="match_parent"
android:layout_width="match_parent"
----
<EditText
android:id="#+id/IngredientsLineEdit"
android:layout_height="match_parent"
android:layout_width="match_parent"
-----
Change from fill_parent to match_parent in all Views.

Related

BottomSheet move to top of screen when changing visibility of its component

I have a bottom sheet with a NestedScrollView inside (see below). When I press on a FAB button, I want to make some parts in this NestedScrollView invisible. But when I change some linearlayouts visibilities to GONE, bottomsheet fly aways from the top.
My XML code:
<?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:id="#+id/messageOptionBottomSheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/back_miscellaneous"
android:gravity="center"
android:orientation="vertical"
app:behavior_peekHeight="0dp"
app:layout_behavior="#string/bottom_sheet_behavior">
<View
android:id="#+id/divider2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/textSecondary" />
<LinearLayout
android:id="#+id/layoutDeleteMessage"
android:layout_width="match_parent"
android:layout_height="#dimen/_35sdp"
android:layout_margin="#dimen/_10sdp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:animateLayoutChanges="true"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="#dimen/_22sdp"
android:layout_height="#dimen/_22sdp"
android:contentDescription="#string/app_name"
android:src="#drawable/ic_remove" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_10sdp"
android:fontFamily="#font/ubuntu_medium"
android:includeFontPadding="false"
android:text="#string/delete_message"
android:textColor="#color/textSecondary"
android:textSize="#dimen/_12ssp" />
<TextView
android:id="#+id/textConfirmDelete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/_10sdp"
android:fontFamily="#font/ubuntu_medium"
android:gravity="end"
android:includeFontPadding="false"
android:text="#string/confirm"
android:textColor="#color/red"
android:textSize="#dimen/_12ssp"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
Your bottom sheet is moving top because you are using
android:animateLayoutChanges="true"
remove this line from your layoutDeleteMessage (Linear layout)
Hope this solve your problem

Android nested layout with layout_weight

I would like to create left and right reserved spaces (LinearLayout) on screen which give me felexiblitiy to ensure my UI is working in different size of screen as I want,
and in middle create a TableLayout to apply views and contorls, everything good great
except TableRow - android:layout_width is became zero, TableLayout width is not really zero however I had to put android:layout_width="0dp" for TableLayout to force android:layout_weight="4" working
how can I tell TableRow to take actual parnt(TableLayout) width
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="#+id/widget33"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1">
</LinearLayout>
<TableLayout
android:id="#+id/widget34"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="4">
<TableRow
android:id="#+id/widget64"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/widget72"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I m here" />
</TableRow>
</TableLayout>
<LinearLayout
android:id="#+id/widget35"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1">
</LinearLayout>

How to display a SeekBar correctly? (layout_weight)

I`m trying to create the following layout:
<?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="match_parent"
android:layout_height="match_parent" >
</TextView>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TextView>
<SeekBar
android:id="#+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TextView>
</LinearLayout>
I`d like to give the 80% of the parent layout to the textView1 and textView2, wrap the SeekBar as much as possible and the rest of the free space give to the textView3.
I`ve tried to:
use layout_weight attributes (respectively - 4, 4, 1, 1) but the last
view overlaps the SeekBar
use layout-weight only with textView1 and textView2, set SeekBar`s height to "wrap_content" and set "match_parent" for the last view
And now I have no more ideas. Have you ever had such a problem?
well to create this layout I would try :
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="4" >
</TextView>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="4" >
</TextView>
<SeekBar
android:id="#+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
</TextView>
make change on weights tu adjust sizes.
let the seek bar to wrap content, give weight on other views.
tell me if that helps.

LinearLayout won't fill parent; instead if fits to the smallest width view in it

I have a view that looks like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout android:id="#+id/header"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:paddingTop="5dp"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp">
<ImageView android:id="#+id/title_icon"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:src="#drawable/title_icon" />
<LinearLayout android:id="#+id/title_layout"
android:layout_toRightOf="#id/title_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<TextView android:id="#+id/title_text"
android:text="#string/activity_complete"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:paddingRight="15dp"
android:textSize="12dp"
android:textStyle="bold"/>
</LinearLayout>
<TextView android:id="#+id/status_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:textSize="8dp" />
</RelativeLayout>
<TextView android:id="#+id/message_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="5dp"
android:paddingLeft="15dp"
android:textSize="10dp"/>
<ImageView android:id="#+id/main_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/grey"
android:padding="5dp"/>
</LinearLayout>
My problem is that the main LinearLayout view doesn't match_parent or fill_parent. It seems to want to only contain the smallest item within it. In my case it will result in a width the same as main_image, cutting off the content of everything else. However, if I set main_image to visibility.gone then it will match the width of message_text.
I've tried removing everything except main_image and the main LinearLayout still only fits the image width.
The other thing is that this layout is inflated into another LinearLayout which is set to fill_parent.
Wrapping the ImageView in another LinearLayout fixed the issue.
I just had this problem -- adding a LinearLayout configured to "match_parent" to another LinearLayout, but the inner layout did not fill the outer one properly.
Initially I was doing this to add the layout:
LinearLayout inner = getLayoutInflater().inflate(R.layout.inner, null);
outer.addView(inner, 0);
After a few minutes of exasperation I tried this instead:
LinearLayout inner = getLayoutInflater().inflate(R.layout.inner, outer);
And inner matched the outer parent width and height.

how to put scrolled textview on secroll layout

i have to use scrolled textview on scrolled layout so if i want to scroll the textview the whole layout scrolled when need just scrolled the textview and when scroll out text-view the whole layout scrolled see the code t
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollViewOne"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="460dp"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="54dp"
android:orientation="vertical" >
</LinearLayout>
<FrameLayout
android:id="#+id/frameLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="247dp"
android:layout_height="240dp"
android:layout_gravity="center_horizontal"
android:scaleType="center"
android:src="#drawable/image1" />
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</FrameLayout>
</LinearLayout>
<TextView
android:id="#+id/lblTextViewBig"
android:layout_width="229dp"
android:layout_height="91dp"
android:layout_gravity="center_horizontal"
android:focusable="true"
android:focusableInTouchMode="true"
android:maxLines="3"
android:scrollbarTrackVertical="#id/lblTextViewBig"
android:scrollbars="vertical"
android:singleLine="false"
android:text="#string/namm" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="300dp"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</ScrollView>
A couple of items:
1) You have a dangling '>' near the end of your code.
2) If you want to just scroll the TextView, then only wrap the textview in the scrollview, see Scroll view for textview in android for an example.

Resources