2017-12-15 10 views
1

私はインフレータを使って子レイアウトからedittextをコピー/インクルードしていますが、アプリケーションが子レイアウトを追加/インクルード/コピーした後、私が欲しいのは、最後の "edittext"の最後にボタンがあることです。ここedittextをインクルードするためにインフレータを使用しているときにボタンが押されない

enter image description here

私のメインのレイアウトです:

<?xml version="1.0" encoding="utf-8"?> 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/main_layout" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <include layout="@layout/stocker_child" /> 

    <Button 
     android:id="@+id/save" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="Simpan" /> 

</LinearLayout> 

</ScrollView> 

、これは子のレイアウトです:

私は子供のレイアウトを膨らませる方法
<?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="60dp"> 

<EditText 
    android:id="@+id/barcodeText0" 
    android:tag="barcodeText0" 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:layout_marginEnd="17dp" 
    android:layout_marginStart="16dp" 
    android:ems="10" 
    android:inputType="textPersonName" 
    app:layout_constraintBottom_toBottomOf="@+id/qtyText0" 
    app:layout_constraintEnd_toStartOf="@+id/qtyText0" 
    app:layout_constraintStart_toStartOf="parent" 
    app:layout_constraintTop_toTopOf="@+id/qtyText0" /> 

<EditText 
    android:id="@+id/qtyText0" 
    android:tag="qtyText0" 
    android:layout_width="78dp" 
    android:layout_height="47dp" 
    android:layout_marginEnd="12dp" 
    android:layout_marginTop="16dp" 
    android:ems="10" 
    android:inputType="textPhonetic|numberDecimal" android:digits="/.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU" 
    app:layout_constraintEnd_toEndOf="parent" 
    app:layout_constraintStart_toEndOf="@+id/barcodeText0" 
    app:layout_constraintTop_toTopOf="parent" /> 
</android.support.constraint.ConstraintLayout> 

と、この:

    val inflater = activity.layoutInflater 
       val myLayout = inflater.inflate(R.layout.stocker_child, mainLayout, false) 

       mainLayout.addView(myLayout) 
       mainLayout.requestFocus() 

答えて

2

mainLayout.addView()は、mainLayoutの最後の項目としてビューを追加します。これはあなたのボタンの上myLayoutを追加する必要があります

mainLayout.addView(myLayout, mainLayout.getChildCount() - 1); 

:異なるメソッドオーバーロードを使用してください。

+0

ありがとう!私の場合は、そのちょうど-1 – Kakashi

関連する問題