Ich kann erfolgreich eine Textansicht zu einer Bildlaufansicht auf einen Klick hinzufügen, wie in den zwei Screenshots gezeigt: screenshot 1 und screenshot 2. Aber was, wenn ich stattdessen die Textansichten zuerst am unteren Rand des Bildschirms hinzufügen möchte und jede hinzugefügte Textansicht die vorherige über sie schiebt, was dann dazu führen würde, dass ich nach oben scrollen anstatt nach unten, um frühere Textansichten zu sehen? Ich habe das schon lange versucht und kann es nicht zur Arbeit bringen. Irgendwelche Vorschläge? Ich versuchte einfach, um die lineare Layout Layout-Schwerkraft zu ändern, die der Scroll-Teil arbeitet, bis in kommt.Versuch zum Hinzufügen von Textansicht auf Schaltfläche klicken mit scrollview
<ScrollView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toTopOf="@+id/editText">
<LinearLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:orientation="vertical"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
</LinearLayout>
</ScrollView>
<EditText
android:id="@+id/editText"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="Enter Text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.508"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/button" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Create"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="1dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginEnd="8dp" />
private LinearLayout layout;
private EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
layout = (LinearLayout) findViewById(R.id.layout);
editText = (EditText) findViewById(R.id.editText);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(onClick());
}
private View.OnClickListener onClick() {
return new View.OnClickListener() {
@Override
public void onClick(View v) {
layout.addView(createNewTextView(editText.getText().toString()),0);
}
};
}
private TextView createNewTextView(String text) {
final LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams
(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
final TextView textView = new TextView(this);
lparams.gravity = Gravity.BOTTOM;
textView.setLayoutParams(lparams);
textView.setText("New text: " + text);
textView.setTextSize(30);;
return textView;
}
danke für die Antwort, aber das relative Layout behebt das Problem nicht. – 4rsenal
können Sie bitte Ihre Aktivitätsklassencodes posten? – FAT
wurde gerade der Aktivitätscode – 4rsenal