ListView Overlays EditText when Scrolling - java

I have the following linear layout. In the below situation, filler layout and the textview turn to View.GONE and the ListView is set to VISIBLE, as well as the editText on top. Everything seems fine, however when I scroll the below happens with the text from the listview overlaying my editText. Also, at the bottom of the screen there is a gap between the end of the listView and the bottom of the screen, which I would not want to be there, I want it to be attached to the bottom of the screen.
<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:background="#45D199"
android:orientation="vertical"
android:id="#+id/main_layout"
android:weightSum="100"
android:clipChildren="false"
tools:context=".City_Search">
<EditText
android:layout_width="fill_parent"
android:textColor="#FFFFFF"
android:id="#+id/edit_txt"
android:textSize="25sp"
android:gravity="center"
android:background="#android:color/transparent"
android:hint="Name of the City..."
android:visibility="invisible"
android:maxLines="1"
android:maxLength="15"
android:textColorHint="#FFFFFF"
android:layout_height="65dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_weight="35"
android:id="#+id/filler_layout"
android:orientation="horizontal"
android:layout_height="0dp"></LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_gravity="center"
android:textColor="#FFFFFF"
android:id="#+id/search_txt"
android:layout_weight="10"
android:textSize="25sp"
android:gravity="center"
android:text="Name of the City..."
android:layout_height="0dp" />
<ListView
android:layout_width="fill_parent"
android:layout_weight="90"
android:visibility="gone"
android:id="#+id/list_view"
android:layout_height="0dp"></ListView>

Try Below code.Its help you something
- <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#45D199"
android:orientation="vertical"
tools:context=".City_Search">
<EditText
android:layout_width="fill_parent"
android:textColor="#FFFFFF"
android:id="#+id/edit_txt"
android:textSize="25sp"
android:gravity="center"
android:background="#android:color/transparent"
android:hint="Name of the City..."
android:visibility="invisible"
android:maxLines="1"
android:maxLength="15"
android:textColorHint="#FFFFFF"
android:layout_height="65dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_weight="35"
android:id="#+id/filler_layout"
android:orientation="horizontal"
android:layout_height="0dp"></LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_gravity="center"
android:textColor="#FFFFFF"
android:id="#+id/search_txt"
android:layout_weight="10"
android:textSize="25sp"
android:gravity="center"
android:text="Name of the City..."
android:layout_height="0dp" />
<ListView
android:layout_width="fill_parent"
android:layout_weight="1"
android:id="#+id/list_view"
android:background="#FFFFFF"
android:visibility="gone"
android:layout_height="0dp"></ListView>
</LinearLayout>

Related

My project has include page for every page. Include layout show well designed in include layout. But the owner page don't show same view

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 >

ScrollView top part is cut off when I added adjustPan so keyboard won't overlap EditText

I have a ScrollView (with a RecyclerView inside) and a RelativeLayout after it which contains EditText. I added
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
for the activity in my manifest file because my keyboard overlaps the EditText but in effect, whenever the keyboard is active, the top part of my ScrollView is cut off.
I have tried using NestedScrollView and setting RelativeLayout android:layout_height="wrap_content" and android:layout_gravity="center" but that doesn't work. Below is the snippet of my code:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/adView"
android:layout_alignParentTop="true"
android:background="#android:color/white"
android:scrollbars="vertical">
<RelativeLayout
...
</RelativeLayout>
<ScrollView
android:id="#+id/news_comments"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_title">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/individual_news_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:orientation="vertical">
// some other layouts
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/individual_news_item"
android:orientation="vertical"
android:paddingEnd="15dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingStart="15dp"
android:paddingTop="15dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="15dp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/ll_message_actions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:layout_gravity="center">
<LinearLayout
android:id="#+id/ll_send_message"
android:layout_width="match_parent"
android:background="#android:color/white"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<github.ankushsachdeva.emojicon.EmojiconEditText
android:id="#+id/et_message_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="#string/keyMessage"
android:inputType="textMultiLine|textNoSuggestions"
android:background="#android:color/transparent"
android:maxLines="4"
android:paddingBottom="5dp"
android:paddingEnd="0dp"
android:paddingLeft="20dp"
android:paddingRight="0dp"
android:paddingStart="20dp"
android:paddingTop="5dp"
android:textColor="#color/light_black"
android:textColorHint="#color/zipt"
android:textSize="17sp"
emojicon:emojiconSize="18sp" />
<ImageButton />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
any ideas how i can solve this?

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

Android layout_weight not working as it should be

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>

stretched out android tablelayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical" android:background="#drawable/background"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_gravity="center">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal"
android:layout_marginBottom="50dp">
<TableLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_marginTop="15dp">
<TextView android:gravity="center" style="#style/entsweep_h_Font"
android:text="numbers" android:id="#+id/entsweep_head_tv">
</TextView>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="center"
android:layout_marginTop="10dp">
<TextView android:layout_width="75dp" android:gravity="center"
android:layout_height="wrap_content" android:text="20" android:id="#+id/ent_submit"
style="#style/entsweep_Button" android:layout_marginRight="10dp">
</TextView>
<TextView android:layout_width="75dp" android:gravity="center"
android:layout_height="wrap_content" android:text="50" android:id="#+id/ent_submit"
style="#style/entsweep_Button" android:layout_marginRight="10dp">
</TextView>
<TextView android:layout_width="75dp" android:gravity="center"
android:layout_height="wrap_content" android:text="100"
android:id="#+id/ent_submit" style="#style/entsweep_Button">
</TextView>
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="center"
android:layout_gravity="center">
<TextView android:gravity="center"
android:text="yet."
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="#+id/ent_submit">
</TextView>
</TableRow>
</TableLayout>
</LinearLayout>
</RelativeLayout>
My problem is the 3 buttons are stretched out differently. I know that because of the textview below the first button would be stretched but I was wondering if there is any way I can make the buttons to stay in the same width and still have the textview exist.
Use the xml attribute android:layout_weight="1" for all the textviews.

Categories