본문 바로가기

구글과인터넷/안드로이드

안드로이드 중간에 낀 레이아웃이 키보드와 붙어서 올라가는 효과 구조 설정해보기

이 구조는 키보드와 같이 올라갈 레이어가 바닥밑 부분에 있지않고 중간에 떠 있을때

키보드가 올라오는 동시 키보드와 딱 붙어서 올라가는 효과를 볼수있다.


프레임 레이아웃으로 레이아웃을 2가지 레이어로 겹쳐서 활용한다.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     android:background="#ff000000"
    >

    <LinearLayout  <!-- 이 레이어부분은 키보드가 떠도 움직이지 않는 고정 레이어 -->
                 android:layout_width="fill_parent"
                 android:layout_height="720dip">

      ... 

     ///각종 구성한 레이어들

      ...

    </LinearLayout>



 <LinearLayout  <!-- 이 부분은 키보드와 함께 움직일 레이어 -->
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="#4000ff00"
      android:gravity="bottom">
        
      <LinearLayout
         android:layout_width="fill_parent"
         android:layout_height="2dip"
         android:background="#ff808080"/>


         <!--중간에 떠있는 채팅창 키보드가 올라올때 키보드와 붙어 올라간다. -->
        <com.common.CChat android:id="@+id/cchat"
                 android:layout_width="fill_parent"
                 android:layout_height="240dip"
                 android:layout_marginTop="0dip"
                 android:layout_marginBottom="0dip"
                 android:visibility="visible"/>


        <!-- 중요포인트 :layout_weight = "1" 을 주고 marginBottom 값을 마이너스를 주어서 CChat를 적절한 위치에 선정해주면 키보드가 올라가면서 이부분의 레이어가 자연스럽게 공간이 줄어들게되고 cchat와  키보드가 붙게된다, -->
         <LinearLayout  
           xmlns:android="http://schemas.android.com/apk/res/android"
           android:orientation="vertical"
           android:layout_width="fill_parent"
           android:layout_height="0dip"
           android:background="#4000ff00"
           android:layout_weight = "1"
           android:layout_marginBottom="-320dip"/> 
        
    </LinearLayout>




</FrameLayout>