2012-04-12 71 views
4

是否可以将小部件放置在其他顶部?Android如何在顶部/上方制作小部件

这样做的真正目的是在softInputKeyboard出现时使按钮可见。此按钮必须始终位于softKeyboard的上方,此滚动条位于此处。

所以也许有其他解决方案来达到目标​​,要求精度,谢谢。

回答

2

这可能与RelativeLayout

LinearLayout可以防止这种情况发生,并按照水平/垂直顺序放置小部件。

+0

明显。我会弄清以下几点。谢谢 ! – 2012-04-12 07:34:49

1

1)软键盘隐藏
enter image description here

2)软键盘可见
enter image description here


Android清单:
(添加android:windowSoftInputMode="adjustResize"到你的活动标签)

<activity 
      android:windowSoftInputMode="adjustResize" 
      android:name="._TestActivity" 
      android:label="@string/app_name" > 


XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/RelativeLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@+id/layout_buttons" 
      android:orientation="vertical" > 

      <EditText 
       android:id="@+id/editText1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="RandomText" 
       android:textAppearance="?android:attr/textAppearanceLarge" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="RandomText" 
       android:textAppearance="?android:attr/textAppearanceLarge" /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="RandomText" 
       android:textAppearance="?android:attr/textAppearanceLarge" /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="RandomText" 
       android:textAppearance="?android:attr/textAppearanceLarge" /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="RandomText" 
       android:textAppearance="?android:attr/textAppearanceLarge" /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="RandomText" 
       android:textAppearance="?android:attr/textAppearanceLarge" /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="RandomText" 
       android:textAppearance="?android:attr/textAppearanceLarge" /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="RandomText" 
       android:textAppearance="?android:attr/textAppearanceLarge" /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="RandomText" 
       android:textAppearance="?android:attr/textAppearanceLarge" /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="RandomText" 
       android:textAppearance="?android:attr/textAppearanceLarge" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/layout_buttons" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:background="@android:color/darker_gray" 
      android:orientation="horizontal" > 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="Ok" /> 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="Cancel" /> 
     </LinearLayout> 

    </RelativeLayout> 
+0

这里是执行ahah。非常感谢你们。 – 2012-04-12 07:37:29

+0

很高兴帮助先生。 :) – 2012-04-12 07:39:33

+0

我有同样的要求,但在这里我正在与片段。碎片中可能是相同的吗? – user512 2016-02-26 06:37:03