2016-01-23 108 views
-1

我正在創建一個控制檯或終端的東西,我遇到了問題。 Normaly我的活動是這樣的:打開EditText鍵盤時移動佈局

enter image description here

,但是當我在的EditText點擊和鍵盤打開我的edittextfield和我的發送按鈕都不見了: enter image description here

,但我想的EditText和發送按鈕在鍵盤上方,所以你可以看到你正在輸入的內容,並且你可以發送它。這是我的xml代碼:

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

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="477dp" 
     android:layout_below="@+id/title" >> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:id="@+id/textView" 
       android:text="Console:" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginRight="0dip" 
       android:gravity="top" 
       android:textSize="20sp" 
       android:textColor="#000000" 
       android:typeface="monospace" 
       android:paddingLeft="0dp"/> 
     </LinearLayout> 
    </ScrollView> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:weightSum="1"> 

     <EditText 
      android:layout_marginLeft="5dp" 
      android:layout_width="163dp" 
      android:layout_height="wrap_content" 
      android:id="@+id/consoleText" 
      android:layout_weight="0.92" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="5dp" 
      android:layout_height="wrap_content" 
      android:text="Send" 
      android:id="@+id/sendButton" 
      android:layout_gravity="right" /> 
    </LinearLayout> 

</LinearLayout> 

也許有人知道,我該如何解決這個問題!在此先感謝,任何幫助表示讚賞:)

回答

1

設置ScrollViewlayout_weight=1應該工作。試試這個

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

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1"> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:id="@+id/textView" 
      android:text="Console:" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="0dip" 
      android:gravity="top" 
      android:textSize="20sp" 
      android:textColor="#000000" 
      android:typeface="monospace" 
      android:paddingLeft="0dp"/> 
    </LinearLayout> 
</ScrollView> 

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

    <EditText 
     android:layout_marginLeft="5dp" 
     android:layout_width="163dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/consoleText" 
     android:layout_weight="0.92" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="5dp" 
     android:layout_height="wrap_content" 
     android:text="Send" 
     android:id="@+id/sendButton" 
     android:layout_gravity="right" /> 
</LinearLayout> 

</LinearLayout> 
+0

很好奏效,你也許知道我能跳/滾動滾動視圖編程結束,因爲我添加文本這個TextView的在我的控制檯,我想sjump到底這個textview裏面我的scrollview每當我發送一個新的命令/按下按鈕:) –

+0

請檢查這個http://stackoverflow.com/questions/3080402/android-scrollview-force-to-bottom滾動'ScrollView'到底部。 – jimmy0251