Android: Keyboard overlaps with the EditText (with printscreens) - android

I have an EditText (that the user can type numbers in),
so when the user clicks on the EditText text box a keyboard with numbers is opened.
as you can see the keyboard hides a small part of the text box.
But when I press a key, for example, 0, it looks ok.
Is there anything I can do (besides putting the EditText higher) so it will looks like it does in the second picture?
Edit: the .xml code:
<?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" android:weightSum="1">
<RelativeLayout android:id="#+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="wrap_content" android:orientation="vertical" android:layout_height="wrap_content" android:id="#+id/linearLayout1" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignParentRight="true">
<android.widget.CheckedTextView android:id="#+id/checkedTextView1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="17sp" android:text="#string/toString"></android.widget.CheckedTextView>
<AutoCompleteTextView android:layout_height="wrap_content" android:id="#+id/autoCompleteTextView1" android:layout_width="fill_parent" android:text="#string/emptyString" android:textSize="17sp" android:gravity="top|left" android:minHeight="62dp">
<requestFocus></requestFocus>
</AutoCompleteTextView>
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="#+id/linearLayout2">
<Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="0.33333333333" android:text="#string/contactsString" android:textSize="17sp" android:id="#+id/contactsButton"></Button>
<Button android:layout_weight="0.33333333333" android:layout_height="wrap_content" android:text="#string/groupsString" android:layout_width="fill_parent" android:id="#+id/groupsButton" android:textSize="17sp"></Button>
<Button android:layout_weight="0.33333333333" android:layout_height="wrap_content" android:text="#string/favouritesString" android:layout_width="fill_parent" android:id="#+id/button3" android:textSize="17sp"></Button>
</LinearLayout>
<TextView android:id="#+id/textView1" android:text="#string/messageString" android:layout_height="wrap_content" android:textSize="17sp" android:layout_width="fill_parent"></TextView>
<EditText android:layout_height="wrap_content" android:id="#+id/editText1" android:layout_width="fill_parent" android:gravity="top|left" android:minHeight="105dp"></EditText>
<TextView android:id="#+id/textView2" android:text="#string/repetition" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="17sp"></TextView>
<Spinner android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="#+id/spinner"></Spinner>
<LinearLayout android:layout_height="wrap_content" android:id="#+id/linearLayout3" android:layout_width="fill_parent">
<ImageView android:src="#drawable/button_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/imageView1" android:layout_weight="0.1"></ImageView>
<EditText android:layout_height="wrap_content" android:id="#+id/timeET" android:inputType="number" android:layout_width="wrap_content" android:layout_weight="0.4"></EditText>
<ImageView android:src="#drawable/button_date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/imageView2" android:layout_weight="0.1"></ImageView>
<EditText android:layout_height="wrap_content" android:id="#+id/dateET" android:inputType="number" android:layout_width="wrap_content" android:layout_weight="0.4" android:layout_marginRight="3dp"></EditText>
</LinearLayout>
<RelativeLayout android:id="#+id/relativeLayout2" android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/linearLayout4" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentLeft="true">
<Button android:layout_weight="0.5" android:layout_height="wrap_content" android:text="#string/button_ok" android:layout_width="fill_parent" android:id="#+id/button4" android:textSize="17sp"></Button>
<Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="#+id/button5" android:layout_weight="0.5" android:text="#string/button_cancel" android:textSize="17sp"></Button>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>

I have tried your XML and yes you are right the problem occur.
To solve the problem I have written this line in my MainActivity.java hope this help to you,And put the layout XML in ScrollView.
Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.temp);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
final EditText time = (EditText)findViewById(R.id.timeET);
time.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
time.requestLayout();
MyActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
return false;
}
});
final EditText date = (EditText)findViewById(R.id.dateET);
date.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
time.requestLayout();
MyActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
return false;
}
});
}
And The XML is Like,
<?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" >
<ScrollView android:id="#+id/scrollView1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:weightSum="1">
---
---
---
</ScrollView>
</LinearLayout>

Change to ScrollView in this way:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true" >
<android.widget.CheckedTextView
android:id="#+id/checkedTextView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textSize="17sp"
android:text="#string/toString" />
<AutoCompleteTextView
android:layout_height="wrap_content"
android:id="#+id/autoCompleteTextView1"
android:layout_width="fill_parent"
android:text="#string/emptyString"
android:textSize="17sp"
android:gravity="top|left"
android:minHeight="62dp" >
<requestFocus></requestFocus>
</AutoCompleteTextView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2" >
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="0.33333333333"
android:text="#string/contactsString"
android:textSize="17sp"
android:id="#+id/contactsButton" />
<Button
android:layout_weight="0.33333333333"
android:layout_height="wrap_content"
android:text="#string/groupsString"
android:layout_width="fill_parent"
android:id="#+id/groupsButton"
android:textSize="17sp" />
<Button
android:layout_weight="0.33333333333"
android:layout_height="wrap_content"
android:text="#string/favouritesString"
android:layout_width="fill_parent"
android:id="#+id/button3"
android:textSize="17sp" />
</LinearLayout>
<TextView
android:id="#+id/textView1"
android:text="#string/messageString"
android:layout_height="wrap_content"
android:textSize="17sp"
android:layout_width="fill_parent" />
<EditText
android:layout_height="wrap_content"
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:gravity="top|left"
android:minHeight="105dp" />
<TextView
android:id="#+id/textView2"
android:text="#string/repetition"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textSize="17sp" />
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner" />
<LinearLayout
android:layout_height="wrap_content"
android:id="#+id/linearLayout3"
android:layout_width="fill_parent" >
<ImageView
android:src="#drawable/button_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView1"
android:layout_weight="0.1" />
<EditText
android:layout_height="wrap_content"
android:id="#+id/timeET"
android:inputType="number"
android:layout_width="wrap_content"
android:layout_weight="0.4" />
<ImageView
android:src="#drawable/button_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:layout_weight="0.1" />
<EditText
android:layout_height="wrap_content"
android:id="#+id/dateET"
android:inputType="number"
android:layout_width="wrap_content"
android:layout_weight="0.4"
android:layout_marginRight="3dp" />
</LinearLayout>
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/linearLayout4"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true" >
<Button
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:text="#string/button_ok"
android:layout_width="fill_parent"
android:id="#+id/button4"
android:textSize="17sp" />
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/button5"
android:layout_weight="0.5"
android:text="#string/button_cancel"
android:textSize="17sp" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>

put the entire view inside a ScrollView and set the android:windowSoftInputMode = adjustPan it will do the trick.
you just need to add this piece of code,
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
Your linear layout here....
</ScrollView>
I have tested it on my HTC Desire and its working fine for me hope it will work for you too.

Set android:windowSoftInputMode on the Activity to "adjustPan":
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing.
Beware of one potential bug when using this technique with a fullscreen activity.

You can give some hints to the system on how to handle this via android:windowSoftInputMode element on the declared activity in the AndroidManifest. Try the "adjustResize" value.
android:windowSoftInputMode

This is a much simpler fix than the accepted answer. The key is the <item name="android:windowSoftInputMode">adjustUnspecified</item> line. Add it to your styles.xml:
<style name="AppTheme" parent="#android:Theme.Holo.Light.DarkActionBar">
<item name="android:alertDialogTheme">#style/iconPopUpDialogTheme</item>
</style>
<style name="DialogAppTheme" parent="AppTheme">
<item name="android:dialogTheme">#style/iconPopUpDialogTheme</item>
</style>
<style name="PopUpDialogTheme">
<item name="android:windowSoftInputMode">adjustUnspecified</item>
</style>

try changing linear layout to scroll view...so that if keyboard comes above editt text user can scroll and type...
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:weightSum="1">
<RelativeLayout android:id="#+id/relativeLayout1"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="wrap_content"
android:orientation="vertical" android:layout_height="wrap_content"
android:id="#+id/linearLayout1" android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" android:layout_alignParentTop="true"
android:layout_alignParentRight="true">
<android.widget.CheckedTextView
android:id="#+id/checkedTextView1" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:textSize="17sp"></android.widget.CheckedTextView>
<AutoCompleteTextView android:layout_height="wrap_content"
android:id="#+id/autoCompleteTextView1" android:layout_width="fill_parent"
android:textSize="17sp" android:gravity="top|left"
android:minHeight="62dp">
<requestFocus></requestFocus>
</AutoCompleteTextView>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#+id/linearLayout2">
<Button android:layout_height="wrap_content"
android:layout_width="fill_parent" android:layout_weight="0.33333333333"
android:textSize="17sp" android:id="#+id/contactsButton"></Button>
<Button android:layout_weight="0.33333333333"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:id="#+id/groupsButton" android:textSize="17sp"></Button>
<Button android:layout_weight="0.33333333333"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:id="#+id/button3" android:textSize="17sp"></Button>
</LinearLayout>
<TextView android:id="#+id/textView1" android:layout_height="wrap_content"
android:textSize="17sp" android:layout_width="fill_parent"></TextView>
<EditText android:layout_height="wrap_content" android:id="#+id/editText1"
android:layout_width="fill_parent" android:gravity="top|left"
android:minHeight="105dp"></EditText>
<TextView android:id="#+id/textView2" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:textSize="17sp"></TextView>
<Spinner android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#+id/spinner"></Spinner>
<LinearLayout android:layout_height="wrap_content"
android:id="#+id/linearLayout3" android:layout_width="fill_parent">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/imageView1"
android:layout_weight="0.1"></ImageView>
<EditText android:layout_height="wrap_content" android:id="#+id/timeET"
android:inputType="number" android:layout_width="wrap_content"
android:layout_weight="0.4"></EditText>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/imageView2"
android:layout_weight="0.1"></ImageView>
<EditText android:layout_height="wrap_content" android:id="#+id/dateET"
android:inputType="number" android:layout_width="wrap_content"
android:layout_weight="0.4" android:layout_marginRight="3dp"></EditText>
</LinearLayout>
<RelativeLayout android:id="#+id/relativeLayout2"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/linearLayout4"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true">
<Button android:layout_weight="0.5" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="#+id/button4"
android:textSize="17sp"></Button>
<Button android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="#+id/button5"
android:layout_weight="0.5" android:textSize="17sp"></Button>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
please make necesscery changes...i have removed strings and drawable src for my convience..u need to change first
linear layout to scrollview..try without this
android:windowSoftInputMode = adjustPan

Add this simple line in your Manifest.xml file:
android:windowSoftInputMode="adjustResize|stateHidden"

Related

Why the TextView in XML layout is not appearing

The problem is with the textview which has the id editTextLabelID as shown below in the code.
I am trying to have a layout designed as follows: label:editText
What I have in the xml layout is, a Relativelayout with green background. And inside it, there is a textview which should be my label and next to it horizontally, there should be an edittext
the problem is, according to the below code, I receive the the below result shown in the image. And the edittext, although it precedes the textview in the xml layout, however it shadows it. how to place both of the textview and edittext horizontally right after each other?
UPDATED
XML Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#color/titleBackGroundColor">
<RelativeLayout
android:id="#+id/RelativeLayout00"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|center_horizontal">
<TextView
android:id="#+id/addLocationActivityTitleID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="#dimen/titlesTextSize"
android:text="#string/addLocationActivityTitle"
android:textColor="#color/titleColor">
</TextView>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/marginTop"
android:background="#color/bodyBackGroundColor">
<TextView
android:id="#+id/editTextLabelID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="#dimen/labelsTextSizes"
android:textColor="#color/contentsColor">
</TextView>
<EditText
android:id="#+id/editTextID"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="#+id/editTextLabelID"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:ems="10"
android:inputType="text">
</EditText>
</RelativeLayout>
</LinearLayout>
UPDATED
Results:
Try This :
<?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="horizontal">
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/marginTop"
android:background="#color/bodyBackGroundColor">
<TextView
android:id="#+id/editTextLabelID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="#dimen/labelsTextSizes"
android:textColor="#color/contentsColor">
</TextView>
<EditText
android:id="#+id/editTextID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:ems="10"
android:inputType="text" >
<requestFocus />
</EditText>
</RelativeLayout>
you are missing these 3 lines in your edit text
android:layout_width="match_parent"
android:layout_toRightOf="#+id/editTextLabelID"
android:layout_alignParentTop="true"
if you don't put it to match parent, it will be very small
the ems value is not a good use here usually
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/marginTop"
android:background="#color/bodyBackGroundColor">
<TextView
android:id="#+id/editTextLabelID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="#dimen/labelsTextSizes"
android:textColor="#color/contentsColor">
</TextView>
<EditText
android:id="#+id/editTextID"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_toRightOf="#+id/editTextLabelID"
android:layout_alignParentTop="true"
android:inputType="text">
</EditText>
</RelativeLayout>
</LinearLayout>
// try this way,hope this will help you...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/addLocationActivityTitleID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="#dimen/titlesTextSize"
android:text="#string/addLocationActivityTitle"
android:textColor="#color/titleColor"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/bodyBackGroundColor">
<TextView
android:id="#+id/editTextLabelID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/labelsTextSizes"
android:textColor="#color/contentsColor"/>
<EditText
android:id="#+id/editTextID"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp"
android:ems="10"
android:inputType="text"/>
</LinearLayout>
</LinearLayout>
in your code, you have many non-usefull layouts, simply you can do it like this :
<TextView
android:id="#+id/addLocationActivityTitleID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="#dimen/titlesTextSize"
android:text="#string/addLocationActivityTitle"
android:textColor="#color/titleColor"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00ff00">
<TextView
android:id="#+id/editTextLabelID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/labelsTextSizes"
android:layout_alignParentLeft="true"
android:layout_marginLeft="4dp"
android:textColor="#color/contentsColor"/>
<EditText
android:id="#+id/editTextID"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/editTextLabelID"
android:layout_marginLeft="4dp"
android:layout_alignTop="#+id/editTextLabelID"
android:layout_alignBottom="#+id/editTextLabelID"
android:layout_width="match_parent"
android:ems="10"
android:inputType="text"/>
</RelativeLayout>

Not happy with my Android UI layout

I am having a heck of time trying to get my UI to look the way I want. Here's what I've got ...
I would like the TextView, the XX:XX:XX, text font to be larger and centered between the EditText and Button. Also how come the user gets the phone keyboard instead of a qwerty keyboard to use to enter text?
Here's my layout XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.5"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.3"
android:text="#string/xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.2"
android:text="#string/add"/>
</LinearLayout>
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
Use the following code to achieve what you want:......
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="18dp"
android:layout_weight="1"
android:text="#string/xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="#string/add"/>
</LinearLayout>
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
please refer this xml all the changes is done tested is also done.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal|center_vertical"
android:textSize="18dp"
android:layout_weight="1"
android:text="hello" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="add"/>
</LinearLayout>
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
You can use relative layout to do that. You can change the font size with android:textSize
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="wrap_content"
android:layout_toRightOf="#id/new_bookmark_name"
android:layout_toLeftOf="#+id/btn_add_new_bookmark"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="#string/xx_xx_xx" />
<Button
android:id="#id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="#string/add"/>
</RelativeLayout>
Replace android:layout_gravity="center" by
android:gravity="center" in your TextView.
and regarding the keyboard layout, it looks like you are trying in the emulator. The emulator shows up 12pad keyboard in portrait mode. You can try in the device.
Please follow below, i have made a sample UI exactly what you have asked for using Relative Layout and by using minimum number of lines. Please have a look and check if can solve the purpose. I have also attached snapshot for the same.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:padding="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<EditText
android:id="#+id/ed_name"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="number" />
<TextView
android:id="#+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ed_name"
android:text="XX:XX:XX"
android:textSize="18dp" />
<Button
android:id="#+id/btn_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text=" add " />
</RelativeLayout>
</RelativeLayout>
About the keypad :Check it on actual device , the device will open its own default keypad.

Issue with EditText in Listview softkeyboard

I have a Listview with row layout contains two textviews and a edittext
In my activity i use
android:windowSoftInputMode="adjustResize|stateHidden"
and in edittext arguments are:
<EditText
android:id="#+id/et_quantity_test"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:inputType="numberSigned"
android:gravity="center_vertical|left"
android:layout_gravity="center_vertical|left"
android:paddingLeft="3dp"
android:imeOptions="actionNext"
android:layout_marginRight="10dp"
></EditText>
The problem : When i click on edittext the keyboard shows but edittext field lost focus and the keyboard type is alphabetic ,not numeric..
Thanks
That is main layout
<?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="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<ImageButton
android:id="#+id/img_back"
android:layout_width="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:layout_height="wrap_content"
android:src="#drawable/navigation_back"
android:layout_alignParentRight="true"/>
<TextView
android:id="#+id/tv_title_testing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/test_title"
android:gravity="center_vertical"
android:layout_centerInParent="true"
android:textAppearance="#android:style/TextAppearance.Holo.Medium"
/>
</RelativeLayout>
<Chronometer
android:id="#+id/chronometer_testing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical|center_horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.65"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:gravity="center_horizontal|center_vertical"
android:text="#string/test_sub_title"
android:textAppearance="#android:style/TextAppearance.Holo.Medium" />
</LinearLayout>
<!-- <RelativeLayout
android:layout_height="match_parent"
android:layout_width="fill_parent"> -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ListView
android:id="#+id/lv_product_items_testing"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="9"
transcriptMode="alwaysScroll"
android:scrollbars="vertical" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/ll_conf"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_confirm_test_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_gravity="center_horizontal"
android:text="#string/test_conf" />
<Button
android:id="#+id/btn_confirm_report"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_gravity="center_horizontal"
android:text="#string/test_report" />
</LinearLayout>
</LinearLayout>
First write down android:windowSoftInputMode="adjustPan" in Activity in Manifest file to set listview and Edittext and delete android:inputType="numberSigned" from Edittext is help to When you click EditText keyboard open with Alphabetic..

Android RelativeLayout overlapping

I've a relative layout in android for a chat application.The problem is that the listview on my screen when grows the last elements are hidden behind the textbox and button which I've placed at the bottom.
I am using the following layout file.
<?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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="#+id/PreviousChatsButton"
android:padding="5dip"
android:text="#string/ViewPreviousChats"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:focusable="true"
>
</TextView>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<TextView android:id="#+id/NoChatsMsg"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/NoNewChatMsg"
/>
<Button
android:id="#+id/SubmitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="#string/Submit"
android:onClick="SubmitButtonClick" />
<EditText
android:id="#+id/Chatbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/SubmitButton"
android:layout_alignBottom="#id/SubmitButton"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/SubmitButton"
android:ems="10"
android:inputType="text" >
</EditText>
</RelativeLayout>
what you want to do is in the LinearLayout do android:layout_above="#+id/Chatbox" that will make sure it does not go below it
//try this its working fine for me
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/PreviousChatsButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:gravity="center_horizontal"
android:padding="5dip"
android:text="ViewPreviousChats" >
</TextView>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/NoChatsMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/NoNewChatMsg" />
<Button
android:id="#+id/SubmitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick="SubmitButtonClick"
android:text="#string/Submit" />
<EditText
android:id="#+id/Chatbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/SubmitButton"
android:layout_alignBottom="#id/SubmitButton"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/SubmitButton"
android:ems="10"
android:inputType="text" >
</EditText>
</LinearLayout>
</LinearLayout>
Use android:layout_above to avoid this problem :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/SubmitButton" ... />
<LinearLayout
android:layout_above="#id/SubmitButton" ... >
...
</LinearLayout>
Note that you have to declare your button before the LinearLayout for this to work.

How to make this Layout

what ever I try it always ends up so the second checkbox in a row doesn't show, and I don't know how to put admob wedget on the bottom of the screen
This is what I'm aiming for, thanks ahead of time:
Try this...the trick is to use relative layout for the outermost layout and nest some linear layouts to get the check boxes to align
<?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">
<LinearLayout android:id="#+id/top_row" android:layout_alignParentTop="true" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_above="#+id/bottom_row">
<EditText android:id="#+id/edit_text1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="edit text"></EditText>
<LinearLayout android:id="#+id/check_box_holder" android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="fill_parent">
<LinearLayout android:id="#+id/check_box_left_col" android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1">
<CheckBox android:id="#+id/CheckBox01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentLeft="true" android:text="CheckBox01"></CheckBox>
<CheckBox android:id="#+id/CheckBox02" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentLeft="true" android:text="CheckBox02"></CheckBox>
</LinearLayout>
<LinearLayout android:id="#+id/check_box_right_col" android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1">
<CheckBox android:id="#+id/CheckBox03" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentLeft="true" android:text="CheckBox03"></CheckBox>
<CheckBox android:id="#+id/CheckBox04" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentLeft="true" android:text="CheckBox04"></CheckBox>
</LinearLayout>
</LinearLayout>
<Button android:id="#+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="button1"> </Button>
<EditText android:id="#+id/edit_text2" android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="edit text2"></EditText>
<Button android:id="#+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="button2"> </Button>
</LinearLayout>
<LinearLayout android:id="#+id/bottom_row" android:layout_alignParentBottom="true" android:orientation="horizontal" android:layout_width="fill_parent" android:gravity="center" android:layout_height="wrap_content" android:background="#88ffffff">
<com.admob.android.ads.AdView
android:id="#+id/ad_block"
android:layout_margin="1px" android:layout_width="350dip" android:layout_gravity="center" android:layout_height="58dip"/>
</LinearLayout>
</RelativeLayout>

Categories

Resources