Android Text Input Special UI Item

不羁岁月 提交于 2019-12-01 14:29:02
Karan

Try setting android:windowSoftInputMode=adjustResize for the activity in AndroidManifest.xml.

You can find details here.

Is this possible using only EditText and Button elements?

Answer-This type of functionality is possible in any type of view

I give just short tutorial on your question Generally we use only linearlayout in xml file.But at view level android gives many more feature like Relative layout and much more.At this time we just discuss about the relative layout because it can solve your purpose.

In Relative layout it not use the android:orientation feature like linear layout it used another feature.In relative layout take some points in your mind...

  1. we always give id to every view using android:id="@+id/GiveName"
  2. for alignment of any view we used android:layout_toLeftOf="@id/givesname" same for
    right,above and below where givesname=id of that view from which this view is align.

    Ex. is gives example with screen shot

    After this i give the sample xml file in which you get the above type of feature in your question

  <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/llWriteCommentWall" android:layout_height="fill_parent"
      android:layout_width="fill_parent" android:background="#ffffff">
      <Button android:id="@+id/btButtonComments"
        android:layout_height="wrap_content"     
        android:layout_width="wrap_content"        
        android:text="Comments" 
        android:layout_alignParentRight="true"  
        android:layout_alignParentBottom="true"/>
      <EditText android:id="@+id/etEdittext"
        android:layout_height="wrap_content" android:layout_width="fill_parent"
        android:hint="Write a comment....   "
        android:layout_marginLeft="2dip" android:layout_marginRight="2dip" 
        android:layout_toLeftOf="@id/btButtonComments" 
        android:layout_alignParentBottom="true"/>
    </RelativeLayout>

ScreenShot of above example

In this Example we used android:layout_alignParentBottom="true" - this attribute is the main reason for view like this,it always align any view in bottom even softkeyboard is shown.it contain boolean value,true gives always align bottom and false nothing.

the other relative attribute is android:layout_alignParentRight="true",android:layout_alignParentLeft="true" ,android:layout_alignParentTop="true"-all attribute give feature as written.

Lastly you include this xml file at any java file through setContentView(xmlFileName)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!