【发布时间】:2018-08-31 00:13:46
【问题描述】:
我正在动态地将视图添加到滚动视图(线性布局)中,它不会显示所有内容。例如,如果我添加 10 个视图(TextView 和 EditView),它将显示为 4,如果我添加更多,例如 200,它将达到 131,但我可以看到下一个视图的开头Like this:
这是 XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="match_parent"
android:fillViewport="true"
tools:context=".FirstActivity"
tools:layout_editor_absoluteY="25dp">
<TextView
android:id="@+id/textView"
android:layout_width="95dp"
android:layout_height="36dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ScrollView
android:id="@+id/scrollView3"
android:layout_width="362dp"
android:layout_height="0dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toTopOf="@+id/button4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.47"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
android:paddingBottom="10dp">
<LinearLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
这是java:
public class FirstActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
LinearLayout layout = findViewById(R.id.layout);
int i = 1;
int a = 1;
int noc = 500;
int heightTV = 100;
int heightET = 10;
int widthTV = 100;
int widthET = 200;
do{
TextView textView = new TextView(this);
textView.setId(i);
String number = Integer.toString(a)+".-";
textView.setY(heightTV);
textView.setX(widthTV);
textView.setText(number);
layout.addView(textView);
EditText editText = new EditText(this);
editText.setId(i);
editText.setHint("Example: 567-ZTY");
editText.setY(heightET);
editText.setX(widthET);
editText.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
layout.addView(editText);
i++;
a++;
heightTV = heightTV + 100;
heightET = heightET + 100;
} while (i<=noc);
}
其他一切似乎都正常。 有什么想法吗?
【问题讨论】:
标签: android scrollview programmatically-created