2014-01-29 48 views
0

我試圖讓EditText字段在選中時滾動到我的cameraPreview上。但是現在它正在調整cameraPreview的大小。我會滿足adjustPan行爲,但我希望actionBar留在屏幕上。我懷疑它可以用scrollView來完成,但是直到我不能阻止cameraPreview調整大小。EditText在焦點上滾動而不調整其他視圖

<RelativeLayout 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" 
tools:context=".MainActivity" > 
    <FrameLayout 
    android:id="@+id/cameraPreview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/transparent" > 

    </FrameLayout> 

<!-- Fix for black overlay on menu --> 
<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/transparent" > 
</FrameLayout> 
<ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:isScrollContainer="true" 
     > 
     <EditText 
     android:id="@+id/inputCode" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:background="@color/White" 
     android:ems="10" 
     android:inputType="textNoSuggestions" 
     android:maxLines="1" 
     android:textColor="@color/Green" 
     android:textSize="32sp" 
     android:layout_alignParentBottom="true" > 

    </EditText> 
</ScrollView> 

deformed apple

回答

0

最後決定滾動整個視圖,包括動作欄

0

我一直在尋找了很久的解決辦法,最後我得到了它;

很簡單,

首先,使用scroll_view爲您查看具有edit_text孩子;

其次,使用Relative_Layout(Linear_Layout沒用)作爲Scroll_View的孩子

然後,你可以看到它的工作原理 注意事項:(1)不要使用layout_align_Parent_Bottom,用戶layout_below代替 (2)你不需要指定window_Soft_Input_Model,默認是OK;

這裏是例子

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

<ScrollView 
    android:id="@+id/scrollView1" 
    android:layout_width="match_parent" 
    android:layout_height="500dp" 
    android:text="@string/hello_world" > 

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

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="64dp" 
      android:text="Button1" /> 

     <Button 
      android:id="@+id/button6" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button6" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button2" /> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button3" /> 

     <Button 
      android:id="@+id/button4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button4" /> 

     <EditText 
      android:id="@+id/editText1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/scrollView1" 
      android:ems="10" > 
     </EditText> 

     <Button 
      android:id="@+id/button8" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button8" /> 

     <Button 
      android:id="@+id/button9" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button9" /> 

     <Button 
      android:id="@+id/button10" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button10" /> 

     <Button 
      android:id="@+id/button5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button5" /> 
    </LinearLayout> 
</ScrollView> 

<LinearLayout 
    android:id="@+id/captionbottomrelativelayout" 
    android:layout_width="320dp" 
    android:layout_height="44dp" 
    android:layout_below="@+id/scrollView1" 
    android:orientation="horizontal" > 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     android:text="Button" />`enter code here` 
</LinearLayout> 

'在這裏輸入

0
android:windowSoftInputMode="stateHidden|adjustResize|adjustPan" 

代碼添加上述行放在清單的活動。

相關問題