Ich möchte zwei lineare Layouts nach einer Layouts zu einer Aktivität programmatisch jeweils der gleichen Breite hinzufügen. Das Problem ist, dass ich die Gewichte dieser Layouts nicht programmatisch einstellen kann. Ich könnte dies innerhalb von XML tun, aber ich möchte dies im Programm tun. hier ist das, was ich will:Geordnetes lineares Android-Layout für benutzerdefiniertes Design
erste Schaltfläche enthält volle Breite des Bildschirms aber nach dieser beide Taste gleiche Breite teilen und so weiter ...
offensichtlich, muß es programmatisch tun.
mein Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@drawable/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".HomeActivity">
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linearLayout1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
</ScrollView>
</LinearLayout>
Code behinds:
Button button = new Button(HomeActivity.this);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, 564);
layoutParams.setMargins(60, 80, 60, 40);
Drawable drawable = Drawable.createFromStream(getAssets().open("image/GridButton/NovoTel_IGW_lg.png"), null);
button.setBackground(drawable);
button.setLayoutParams(layoutParams);
linearLayout.addView(button);
Ich habe Ausgabe wie folgt:
Bitte legen nahe, was der beste Weg ist.
Vielen Dank. Es erfüllt meine Anfrage. –