Ich versuche programmgesteuert Formularfelder aus einer HTML-Datei zu einem LinearLayout hinzugefügt. Ich habe eine nächste Taste an der Unterseite, aber es wird immer im Display abgeschnitten. Ich habe es auf einem Tablet versucht und es erscheint immer noch nicht.Android ScrollView wird unten abgeschnitten
Hier ist ein Screenshot der App:
Wie Sie sehen können, werden die Elemente wiedergegeben zu werden, aber die letzte läuft auf den Bildschirm aus irgendeinem Grund aus.
Fragment XML:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".dataInput.PropertyInfoFragment"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<ScrollView
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linear_layout_property_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
<Button
android:id="@+id/nextButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/next"
android:background="@color/colorPrimary"
android:textColor="@android:color/white"/>
</LinearLayout>
</ScrollView>
</FrameLayout>
Aufruf Aktivität XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".dataInput.DataInputActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_media_play" />
</android.support.design.widget.CoordinatorLayout>
ich eine Methode nenne formInflator
, die ich in dem Fragment des aus onCreateView
und die Linearlayout aus dem Fragment geht und einen Elements
Objekt (aus der Jsoup-Bibliothek), die alle Elemente enthält, die ich in das LinearLayout einfügen möchte:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_property_info, container, false);
nextButton = (Button) view.findViewById(R.id.nextButton);
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onButtonPressed();
}
});
helpers.formInflator((LinearLayout) view.findViewById(R.id.linear_layout_property_info), generator.propertyTextElements);
return view;
}
Hier ist die Methode formInflator
:
public void formInflator(LinearLayout parentLayout, Elements formElements) {
TextInputLayout index = null;
for(Element textField : formElements) {
TextInputEditText editText = new TextInputEditText(context);
editText.setId(View.generateViewId());
editText.setHint(textField.id());
editText.setText(textField.text());
LinearLayout.LayoutParams editTextParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
editText.setLayoutParams(editTextParams);
TextInputLayout textInputLayout = new TextInputLayout(context);
textInputLayout.setId(View.generateViewId());
textInputLayout.setTag(textField.id());
RelativeLayout.LayoutParams textInputLayoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
if (index == null)
index = textInputLayout;
else
textInputLayoutParams.addRule(RelativeLayout.BELOW, index.getId());
textInputLayout.setLayoutParams(textInputLayoutParams);
textInputLayout.addView(editText, editTextParams);
parentLayout.addView(textInputLayout, textInputLayoutParams);
index = textInputLayout;
}
}
Jede Idee, was ich falsch mache?
wenn es sicherlich ein Scrollview ist können Sie einfach nach oben, den Rest "cut-off" Gehalt zu sehen? Was ist das beabsichtigte Verhalten, das du erreichen willst? – wanpanman
@wanpanman Ich glaube, ich habe meine Frage nicht richtig formuliert. Das Problem ist, dass nach allen EditText-Ansichten eine Schaltfläche vorhanden sein sollte. Die ScrollView scrollt jedoch nicht den ganzen Weg nach unten. Was ich auf dem Screenshot gezeigt habe, ist der weiteste Weg. – Mak
Ich habe ein Gefühl wegen der Aktionsleiste. Ich stehe vor demselben Problem. Ich verwende eine Tabbed-Aktivität, und innerhalb der Registerkarten habe ich 'EditText's. Anfangs wird der Boden wie OPs abgeschnitten. Aber sobald ich einen 'EditText' aktiviere und die Soft-Tastatur auftaucht, verschwindet die Aktionsleiste (das ist ein anderes Problem, das ich nicht lösen kann), aber die' ScrollView' funktioniert perfekt, auch nachdem die Tastatur entfernt wurde (Aktionsleiste fehlt noch). – xSooDx