gpt4 book ai didi

java - 如何创建终端/控制台

转载 作者:行者123 更新时间:2023-11-29 20:10:50 31 4
gpt4 key购买 nike

我想创建一个终端/控制台,用户可以在其中输入命令。我知道 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 处理的图片来展示我想做的事情,所以在这种情况下每次我输入命令时,我都会使用示例“命令一”、“命令二”和“命令三”,所以和如果我在每个按钮之后单击发送按钮,它们应该如下所示:

enter image description here

所以如果文本到达这个黑条:

enter image description here

上面添加的文本应该被推送到 ScrollView 中,每个新文本也将成为 ScrollView 的一部分,以便您稍后可以滚动浏览命令。我知道这是一篇很长的文章,我希望我想做的很清楚,并且有人会知道我该怎么做。所以提前致谢:)

最佳答案

对于此任务,您应该考虑使用 ListView 并将每个命令添加为该 View 中的新行。它还会注意滚动,您的文本不会与您的 EditText 冲突。

关于java - 如何创建终端/控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34966527/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com