我想创建一个终端/控制台,用户可以在其中输入命令。我知道java的,但我是新来的XML,所以我想知道我怎么可以在文字产卵的文本,如果它得到长期应该是滚动的,这里有一个画面:如何创建终端/控制台
和这里的我为它的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:
所以,如果文本到达该黑条:
上面添加的文本应得到推在一个滚动视图和每一个新的文本也将获得滚动视图的一部分,从而使您稍后可以滚动浏览您的命令。 我知道这是一个很长的帖子,我希望很清楚我想做什么,有人会知道我该如何做到这一点。因此,在此先感谢:)
提示:为什么使用** 2 **嵌套LinearLayouts而不是** 1 **单个RelativeLayout? –
我不是新来的xml和android应用程序制作,对我来说它运行良好,所以我认为我可以这样做:S –
好吧,嵌套布局总的来说是避免的,如果你关心表演。永远记住:越平坦,越好。 –