2014-09-11 204 views
-1

我正在制作一个应用程序,我想要一个线性布局显示在键盘上。当用户关闭键盘时,线性布局也应该消失。 我希望它是这样的在键盘上显示一个视图

enter image description here

布局我想要什么

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" > 

     <RelativeLayout 
      android:id="@+id/root" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" > 

       <ImageView 
        android:id="@+id/iv_Img1" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:scaleType="fitXY" /> 

       <ImageView 
        android:id="@+id/iv_Img2" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:scaleType="fitXY" /> 
      </LinearLayout> 
     </RelativeLayout> 

     <ImageView 
      android:id="@+id/iv_Edit" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:padding="5dp" 
      android:scaleType="center" 
      android:src="@drawable/cam" /> 
    </RelativeLayout> 

    <LinearLayout 
     android:id="@+id/llEditOptions" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="5dp" 
     android:layout_marginTop="5dp" 
     android:layout_weight="0" 
     android:visibility="gone" > 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" > 

      <ImageView 
       android:id="@+id/iv_background" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerVertical="true" 
       android:layout_marginRight="50dp" 
       android:layout_toLeftOf="@+id/iv_font" 
       android:scaleType="center" 
       android:src="@drawable/save_1" /> 

      <ImageView 
       android:id="@+id/iv_font" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:scaleType="center" 
       android:src="@drawable/cam" /> 

      <ImageView 
       android:id="@+id/iv_size" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerVertical="true" 
       android:layout_marginLeft="50dp" 
       android:layout_toRightOf="@+id/iv_font" 
       android:scaleType="center" 
       android:src="@drawable/share_1" /> 
     </RelativeLayout> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/llCamOptions" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="5dp" 
     android:layout_marginTop="5dp" 
     android:layout_weight="0" > 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <ImageView 
       android:id="@+id/iv_Save" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerVertical="true" 
       android:layout_marginRight="50dp" 
       android:layout_toLeftOf="@+id/iv_Camera" 
       android:scaleType="center" 
       android:src="@drawable/save_1" /> 

      <ImageView 
       android:id="@+id/iv_Camera" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:scaleType="center" 
       android:src="@drawable/cam" /> 

      <ImageView 
       android:id="@+id/iv_Share" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerVertical="true" 
       android:layout_marginLeft="50dp" 
       android:layout_toRightOf="@+id/iv_Camera" 
       android:scaleType="center" 
       android:src="@drawable/share_1" /> 
     </RelativeLayout> 
    </LinearLayout> 

</LinearLayout> 

这是iOS手机,但是我们可以实现在安卓这个功能???

+1

你尝试过什么吗?你在哪里编码? – Westranger 2014-09-11 12:54:50

+0

不,我没有找到任何如何做到这一点。请问你能指导我吗? – user3917131 2014-09-11 12:55:44

+0

aadd您的布局代码有问题 – 2014-09-11 12:56:06

回答

3

当显示键盘时,整个布局被压扁,因为可用空间较少。您只需将LinearLayout对齐屏幕底部,它将直接显示在键盘上方。例如,你可以使用一个布局是这样的:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 


    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="60dp" 
     android:clipToPadding="false"> 

     <RelativeLayout 
      android:id="@+id/rlContent" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      ... // The content of your layout goes here    

     </RelativeLayout> 

    </ScrollView> 

    <LinearLayout 
     android:id="@+id/llFooter" 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     android:orientation="horizontal" 
     android:layout_alignParentBottom="true"> 

     // This LinearLayout will be aligned to the 
     // bottom of the screen and displayed above your keyboard 

    </LinearLayout> 

</RelativeLayout> 

ScrollView是只是为了让您的布局滚动当键盘打开并没有足够的空间来再一次显示它的全部。底部的LinearLayout将独立定位在屏幕的底部,并与其他部分重叠。

ScrollView也有一个填充,它等于页脚View的大小,并具有clipToPadding设置为false。这意味着ScrollView可以使用填充来显示内容。你需要这个,否则你的布局的底部将隐藏在底部的LinearLayout后面。滚动时,您可以使LinearLayout稍微透明,以获得更好的效果。

+0

但是,当我的键盘被隐藏,我不想显示达布局 – user3917131 2014-09-11 13:01:33

+0

@ user3917131所以只是隐藏它。究竟是什么问题? – 2014-09-11 13:03:56

+0

我编程式地添加了一个textview.But当我打开键盘时,textview正在键盘下方的那个方法 – user3917131 2014-09-11 13:13:35