2016-01-23 136 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