java - Fixed position for edittext in android layout -


could explain me, how can place textview, edittext , button in center of activity?

must so:

  1. textview in center below.
  2. edittext , near button (these 2 elements in center togehter).

i have want, when try fill edittext, have softkeybord , activity title jumps top , user can't see it.

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"                 xmlns:tools="http://schemas.android.com/tools"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:paddingleft="@dimen/activity_horizontal_margin"                 android:paddingright="@dimen/activity_horizontal_margin"                 android:paddingtop="@dimen/activity_vertical_margin"                 android:paddingbottom="@dimen/activity_vertical_margin"                 tools:context=".addlist">       <linearlayout             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:layout_alignparentbottom="true"             android:id="@+id/input"             android:gravity="center|center_vertical"             android:layout_alignparenttop="false"             android:layout_centervertical="true">          <edittext                 android:id="@+id/edittext"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_weight="1"                 android:ems="10"                 android:singleline="true">              <requestfocus />         </edittext>          <button                 android:id="@+id/button"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_weight="0"                 android:text="add" />     </linearlayout>      <linearlayout             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:id="@+id/linearlayout"             android:layout_alignparentleft="true"             android:layout_alignparenttop="false"             android:layout_alignparentright="true"             android:layout_alignparentbottom="false"             android:layout_alignwithparentifmissing="false"             android:baselinealigned="false"             android:gravity="center|center_vertical"             android:paddingbottom="70dp"             android:layout_centerinparent="true">          <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="skleroshop list name"                 android:id="@+id/textview2"                 android:focusable="false"                 />     </linearlayout>   </relativelayout> 

/now/

<?xml version="1.0" encoding="utf-8"?> <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="fill_parent"               android:orientation="vertical"               tools:context=".addlist" >      <linearlayout             android:id="@+id/input1"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:layout_gravity="center"             android:gravity="center|center_vertical" >          <textview                 android:id="@+id/txt"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_gravity="center_vertical"                 android:gravity="center"                 android:singleline="true"                 android:text="hello" >         </textview>     </linearlayout>      <linearlayout             android:id="@+id/input"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:layout_gravity="center_vertical"             android:orientation="horizontal"             android:gravity="center_vertical">          <edittext                 android:id="@+id/edittext"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_weight="1"                 android:ems="10"                 android:singleline="true" >              <requestfocus />         </edittext>          <button                 android:id="@+id/button"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_weight="0"                 android:text="add" />     </linearlayout>  </linearlayout> 

normal screen http://i41.tinypic.com/13yjyut.png softkeybord http://i43.tinypic.com/20j1nko.png

if using linearlayout, may specify, gravity attribute center child view.

android:layout_gravity="center_horizontal" 

if using relative layout parent layout may use attribute center child view.

android:layout_centerhorizontal="true"

see help

android soft keyboard resize layout

and android developer reference

http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

add attribute activity

 android:windowsoftinputmode="statevisible|adjustresize"  

and change layout to:

 <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"      xmlns:tools="http://schemas.android.com/tools"      android:id="@+id/relativelayout1"      android:layout_width="match_parent"      android:layout_height="match_parent"      android:gravity="center_vertical"      android:orientation="vertical"      android:paddingbottom="@dimen/activity_vertical_margin"      android:paddingleft="@dimen/activity_horizontal_margin"      android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context=".mainactivity" >  <textview     android:id="@+id/textview1"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_centerhorizontal="true"     android:layout_centervertical="true"     android:gravity="center|center_vertical"     android:text="medium text"     android:textappearance="?android:attr/textappearancemedium" />  <edittext     android:id="@+id/edittext1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbaseline="@+id/button1"     android:layout_alignbottom="@+id/button1"     android:layout_toleftof="@+id/button1"     android:ems="10" />  <button     android:id="@+id/button1"     style="?android:attr/buttonstylesmall"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignright="@+id/textview1"     android:layout_below="@+id/textview1"     android:onclick="sum"     android:text="sum" />   </relativelayout> 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -