因此,当前我有一个EditText字段和一个按钮,我希望每次按下该按钮时,都可以在屏幕底部添加名称,但要继续将其添加到屏幕底部,而不是一行。它目前仅在一行上打印,我不知道如何在要添加的文本上放大字体。很抱歉这个愚蠢的问题。这就是我在主文件和XML bc中拥有的内容,它不允许我在其下面发布
package com.example.bryce.
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.util.Log;
import android.view.View;
import android.content.
public class MainActivity extends
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final LinearLayout mLayout=findViewById(R.id.linearLayout);
final EditText mEditText=findViewById(R.id.StudentNameEdt);
final Button mButton=findViewById(R.id.insertButton);
TextView textView=new TextView(this);
textView.setText("New TExt");
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mLayout.addView(createNewTextView(mEditText.getText().toString()));
}
});
}
private TextView createNewTextView(String text)
{
final LinearLayout mLayout=findViewById(R.id.linearLayout);
String newLine=System.getProperty("line.separator");
final LinearLayout.LayoutParams lparams =new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
RelativeLayout.LayoutParams params= (RelativeLayout.LayoutParams) mLayout.getLayoutParams();
final TextView textView=new TextView(this);
textView.setLayoutParams(lparams);
textView.setText("New texT:: "+text+newLine);
return textView;
}
}
And here is the XML
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="900dp"
tools:context=".MainActivity">
<TextView
android:id="@+id/NewClassTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Welcome!"
android:textSize="30sp"
android:textStyle="bold"
android:typeface="serif"
app:fontFamily="sans-serif-smallcaps" />
<TextView
android:id="@+id/WelcomeAgain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="@+id/NewClassTitle"
android:text="Fill out the Form Below to Register"
android:textSize="20sp"
android:textStyle="bold"
android:typeface="serif"
app:fontFamily="sans-serif-smallcaps" />
<EditText
android:id="@+id/ClassNumEdt"
android:layout_width="324dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="222dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Class
<Button
android:id="@+id/insertButton"
android:layout_width="wrap_content"
android:layout_height="38dp"
android:layout_above="@+id/StudentView"
android:layout_toStartOf="@+id/NewClassTitle"
android:text="Insert"
android:textSize="14sp" />
<EditText
android:id="@+id/StudentNameEdt"
android:layout_width="337dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="295dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Student Name" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="0dp"
android:orientation="horizontal"></LinearLayout>
</RelativeLayout>
</ScrollView>
答案 0 :(得分:0)
您的LinearLayout
方向似乎是horizontal
。您应该在vertical
处添加以下行。
话虽如此,请考虑为任务使用RecyclerView
。