2016-01-23 69 views
-1

我想创建一个终端/控制台,用户可以在其中输入命令。我知道java的,但我是新来的XML,所以我想知道我怎么可以在文字产卵的文本,如果它得到长期应该是滚动的,这里有一个画面:如何创建终端/控制台

enter image description here

和这里的我为它的XML cpde:

<?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"> 

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

     <EditText 
      android:layout_width="175dp" 
      android:layout_height="wrap_content" 
      android:id="@+id/consoleText" 
      android:layout_gravity="bottom" 
      android:hint="Command" 
      android:layout_weight="0.99" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Send" 
      android:id="@+id/sendButton" 
      android:layout_gravity="bottom" /> 
    </LinearLayout> 

</LinearLayout> 

,这里是我的获取文本代码:

public class FragmentConsole extends Fragment{ 
    EditText text; 
    Button button; 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View view = inflater.inflate(R.layout.console, 
       container, false); 
     button = (Button) view.findViewById(R.id.sendButton); 
     text = (EditText)view.findViewById(R.id.consoleText); 
     button.setOnClickListener(new View.OnClickListener() 
     { 
      @Override 
      public void onClick(View v) 
      { 
       Log.v("EditText", text.getText().toString()); 
      } 
     }); 
     return view; 
    } 
} 

因此,我会使用一些Photoshop处理的图片显示我想做的事情,所以每次我在这种情况下输入一个命令,我将使用示例“命令一”,“命令二”&“命令三”,所以如果我点击发送按钮后,他们每个人应该像这样apper:

enter image description here

所以,如果文本到达该黑条:

enter image description here

上面添加的文本应得到推在一个滚动视图和每一个新的文本也将获得滚动视图的一部分,从而使您稍后可以滚动浏览您的命令。 我知道这是一个很长的帖子,我希望很清楚我想做什么,有人会知道我该如何做到这一点。因此,在此先感谢:)

+0

提示:为什么使用** 2 **嵌套LinearLayouts而不是** 1 **单个RelativeLayout? –

+0

我不是新来的xml和android应用程序制作,对我来说它运行良好,所以我认为我可以这样做:S –

+0

好吧,嵌套布局总的来说是避免的,如果你关心表演。永远记住:越平坦,越好。 –

回答

1

对于此任务,您应该考虑使用ListView并在此视图中添加每个命令作为新行。它也会照顾滚动,你的文本不会与你的EditText混淆。

+0

这是另一种可能性。甚至更好,因为通过这样做,可以重新执行命令而不必再次键入它们。 –