Попытка добавить новый TextView в нижнюю часть экрана и сложить их - PullRequest
0 голосов
/ 19 сентября 2018

Так что в настоящее время у меня есть поле EditText и кнопка, и я хочу каждый раз, когда эта кнопка нажимается, добавлять имя в нижней части экрана, но продолжаю добавлять их в нижней части экрана, а не в одну строку.В настоящее время он печатает только в одну строку, и я не знаю, как увеличить шрифт в добавляемом тексте.Извините за тупой вопрос.Это то, что у меня есть в основном файле и в XML-коде, поэтому я не могу публиковать его прямо под ним

    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>

1 Ответ

0 голосов
/ 19 сентября 2018

Ваша LinearLayout ориентация выглядит как horizontal.Это должно быть vertical где вы ожидаете, что строки будут добавлены ниже.

Как говорится, рассмотрите возможность использования RecyclerView для этой задачи.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...