Ich habe eine XML wie unten.Android-Komponenten programmatisch setzen
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<LinearLayout
android:id="@+id/etMsisdn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/allView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/msisdn"
android:layout_marginRight="4dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorPrimaryDark"
android:hint="MSISDN"
android:inputType="numberDecimal"
/>
<ImageView
android:layout_width="60px"
android:layout_height="match_parent"
android:src="@drawable/scan"/>
</LinearLayout>
</LinearLayout>
............
Another View
............
</LinearLayout>
Wie kann ich EditText und Image programmatisch in der horizontalen Linearlayout (AllView) und fügen Sie den AllView innerhalb Vertical Linearlayout (etMsisdn) hinzufügen, während das gleiche Attribut wie in XML zu halten.
Die EditText und Image r unter dem msisdn EditText sollte
Haben diese bereits ,,, aber könnten nicht bekommen EditText und Imageview horizontal ausgerichtet – BrenDonie
Das ist etwas anderes. Sie können die erforderlichen LayoutParams manuell hinzufügen (siehe [diese Antwort in SO] (https://stackoverflow.com/questions/5715612/how-to-set-setlayoutparams-for--linearlayout-elements)) oder Sie könnten a Layout (siehe [diese Antwort in SO] (https://stackoverflow.com/questions/5342121/inflate-a-view-layout-into-another-layout#5343733)). –
Ich habe die Antwort mit den vorherigen Informationen aktualisiert. –