I am having a editText and a listview in a single layout .But on clicking editText its height getting decrease like this
Before Click :
On Click :
Here is my XML :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent_clients_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffffff"
android:orientation="vertical" >
<EditText
android:id="#+id/search_button"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5.0dip"
android:layout_weight="0.9"
android:background="#drawable/edbackground"
android:drawableLeft="#drawable/search"
android:drawablePadding="10.0dip"
android:hint="search clients"
android:textColor="#color/gray"
android:textSize="15.0dip" />
<ListView
android:id="#+id/clients_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5.0dip"
android:layout_weight="0.1"
android:background="#android:color/white" />
</LinearLayout>
Just put android:layout_height="wrap_content" instead of android:layout_height="fill_parent" and also remove android:layout_weight="0.9" to EditText
Remove weight and put wrap_content for height of EditText
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent_clients_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffffff"
android:orientation="vertical" >
<EditText
android:id="#+id/search_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher"
android:drawableLeft="#drawable/ic_launcher"
android:drawablePadding="10.0dip"
android:hint="search clients"
android:textColor="#123456"
android:textSize="15.0dip" />
<ListView
android:id="#+id/clients_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5.0dip"
android:layout_weight="0.1"
android:background="#android:color/white" />
</LinearLayout>
This should work
When you click on your edittext, soft-input comes up and android adjust screen contents sometimes. This is reason your edittext is looking cropped. To prevent this, in your Manifest.xml where you have defined your activity, add following line in your Activity tag:-
android:windowSoftInputMode="adjustNothing"
This will work.
Related
I am working on an app and have a problem.
I have an vieww like the image below with an image and an edittext field the right position. But when i click on the edittext field and it gets the focus it pushes the other view up.
I have the full screen flag and if i dont use that it works perfect and the image keeps theire position and dont pushed up. I need that with full screen flag.
Is there someone who have some example or can help me. I have used the 'windowSoftInputMode' with all the posibles values.
Here my layout code and examples how it now works and how it needs to be.
xml layout source:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:fillViewport="true"
android:orientation="vertical"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical|none" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<!-- layout for images -->
<RelativeLayout
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="top" >
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/image"
android:contentDescription="TODO"/>
</RelativeLayout>
<!-- layout for edit text -->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:layout_alignTop="#id/imageview"
>
<EditText
android:id="#+id/tekstbox"
android:imeOptions="flagNoExtractUi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Here is the image how i start in the activity
When i click in the edittext field i want my view to react as below:
But when the edittext gots focus it pushes everything up like below:
Does someone know how to solve this with the fullscreen flag on?
Thanks.
User this line of code in your Manifest.xml. In the activity where the problem is occuring
<activity
android:windowSoftInputMode="stateVisible|adjustNothing">
</activity>
Add the below line in your manifest file in activity tag:
android:windowSoftInputMode="adjustResize"
and add ScrollView in your layout file like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:fillViewport="true"
android:orientation="vertical"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical|none" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<!-- layout for images -->
<RelativeLayout
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="top" >
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/image"
android:contentDescription="TODO"/>
</RelativeLayout>
<!-- layout for edit text -->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:layout_alignTop="#id/imageview"
>
<EditText
android:id="#+id/tekstbox"
android:imeOptions="flagNoExtractUi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Add the below line in your manifest file in activity tag:
android:windowSoftInputMode="adjustPan|stateHidden"
I have this xml file as a layout of an appwidget:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#android:color/black" >
<!-- ListView to be shown on widget -->
<ListView
android:id="#+id/listViewWidget"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/refresh_appwidget"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="refresh"
/>
</LinearLayout>
The button is not displayed, and I don't know the cause. I tested layout_with match_parent but always the same result.
How can I fix this issue?
Set a fixed height for the listview for example android:layout_height="400dp" in LinearLayout.
Or use a RelativeLayout
Or add your button as a footer to listview. So you can see the button when you scroll down
Or add your button as a header to listview.
With Relative layout you can place the button at the top or button and relative tot eh button you can place your listview.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="#android:color/black"
android:layout_height="fill_parent" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Button" />
<ListView
android:id="#+id/listView1"
android:layout_above="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
</ListView>
</RelativeLayout>
Try with RelativeLayout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#android:color/black" >
<!-- ListView to be shown on widget -->
<ListView
android:id="#+id/listViewWidget"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/refresh_appwidget"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="refresh"
/>
</RelativeLayout>
I try and see the Button but dont see the List
I am using FrameLayout in which I am having a search Textbox and Button and a ListView to be displayed in the next line of the TextBox
My layout is like this ,
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="#drawable/pattern1" />
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="top" >
<Button
android:id="#+id/btnadd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="addCustomers"
android:text="Add"
android:textColor="#000000" >
</Button>
<EditText
android:id="#+id/edtSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:ems="10"
android:hint="Search"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="60dp"
android:gravity="bottom"
android:orientation="vertical">
<ListView
android:id="#+id/list_customers"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|center_horizontal" >
</ListView>
</LinearLayout>
</FrameLayout>
I am using this TextView to diplay List item in the ListView,
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/txtsimple_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:gravity="center_vertical"
android:textSize="20sp"
android:textStyle="bold" />
I have given margin top attribute for the ListView, but even though it overlaps on the Button and EditText controls.
I am using a FrameLayout but of no use. Please suggest me any help!!
Any help is appreciated!!
You should use LinearLayout as parent, just set android:orientation="vertical".
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="#drawable/pattern1" />
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="top" >
...
</LinearLayout>
<ListView
android:id="#+id/list_customers"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|center_horizontal" >
...
</ListView>
</LinearLayout>
FrameLayout has no 'rules of placement' so everything just stacks on to each other.
Instead, use a LinearLayout with android:orientation="vertical"
or use a RelativeLayout and add positioning values to the childs, such as android:layout_below
+1 Neoh and remove imageview, instead put the image as background image attribute at parent view
android:background="#drawable/pattern1"
FrameLayout are used very less,beacuse they are used to display single view or views which overlaps each other.
So you should use RelativeLayout.
FrameLayout is not the best option. You can use other layouts, eg, GridLayout, RelativeLayout or ListView.
I have two edittext views. One of them has only one line, its the title. But the other one should fill the linearlayout to the end, but it doesn't.
I updated the code so this is my whole xml for this app. I hope someone can find what's wrong. The part that i want to form like this is the part inside the LinearLayout named addView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#ffffff">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/addButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/addbuttonstyle"
android:layout_weight="20"/>
<ImageView
android:id="#+id/titleView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/titleview"
android:layout_weight="60"/>
<Button
android:id="#+id/orderButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/orderbuttonstyle"
android:layout_weight="20"/>
</LinearLayout>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/addView"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:id="#+id/textBoxTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="note title"
android:singleLine="true"
/>
<EditText
android:id="#+id/textBoxContent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:hint="content"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/backgroundLayout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/background"
/>
</FrameLayout>
I changed textBoxTitle's height to wrap_content and I see this:
Is this what you were hoping for? Also if you want content to appear in the upper-left corner use this attribute:
<EditText
...
android:gravity="top"
/>
So i found what was wrong.
I needed to set layout_height (of the textBoxContent view) to 0dp and layout_weight (of the textBoxContent view) to 1.
The first view should have android:layout_width="wrap_content"
I have edittext and a button below edittext.
edittext has width as fill_parent and height as wrap_content.
My messages covers full screen, due to this my button is not visible it hides below virtual keyboard
can any one sort this problem.
Thanks.
I've had the most success with something similar, but not identical to, Andrew's solution:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="#+id/myedittext"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/mybutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="this is my button"/>
</LinearLayout>
Try inserting this in your layout file where your edittext is called out:
android:layout_above="#+id/ID OF YOUR BUTTON HERE"
Also, your button at the bottom may require:
android:layout_alignParentBottom="true"
Assuming you WANT the EditText to cover all of the screen except for the button...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="#+id/myedittext"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<Button
android:id="#+id/mybutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="this is my button"/>
</LinearLayout>