我想以类似的颜色模式动态添加按钮,如附带的代码片段所示。我已经看到了各种答案,但没有人满足我的需要。也想要为这六个按钮进行放置。 Inshort我想用新的按钮id和按钮文本复制这个xml。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:layout_width="wrap_content"
android:layout_height="120dp"
android:text="Prospects"
android:id="@+id/buttonExploreOne"
android:layout_alignTop="@+id/button2ExploreOne"
android:layout_alignLeft="@+id/button3ExploreOne"
android:layout_alignStart="@+id/button3ExploreOne"
android:layout_alignRight="@+id/button3ExploreOne"
android:layout_alignEnd="@+id/button3ExploreOne"
android:background="#22b14c"
android:textColor="#ffffff"/>
<Button
android:layout_width="wrap_content"
android:layout_height="120dp"
android:text="Research"
android:id="@+id/button2ExploreOne"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/button4ExploreOne"
android:layout_alignStart="@+id/button4ExploreOne"
android:layout_marginTop="130dp"
android:layout_alignRight="@+id/button4ExploreOne"
android:layout_alignEnd="@+id/button4ExploreOne"
android:background="#6d6e71"
android:textColor="#ffffff"/>
<Button
android:layout_width="wrap_content"
android:layout_height="120dp"
android:text="Connect"
android:id="@+id/button3ExploreOne"
android:layout_marginTop="270dp"
android:layout_alignLeft="@+id/button6ExploreOne"
android:layout_alignStart="@+id/button6ExploreOne"
android:layout_alignRight="@+id/button6ExploreOne"
android:layout_alignEnd="@+id/button6ExploreOne"
android:background="#e39b35"
android:textColor="#ffffff"/>
<Button
android:layout_width="wrap_content"
android:layout_height="120dp"
android:text="Build"
android:id="@+id/button4ExploreOne"
android:layout_alignTop="@+id/button3ExploreOne"
android:layout_alignLeft="@+id/button5ExploreOne"
android:layout_alignStart="@+id/button5ExploreOne"
android:layout_alignRight="@+id/button5ExploreOne"
android:layout_alignEnd="@+id/button5ExploreOne"
android:background="#00aeef"
android:textColor="#ffffff"/>
<Button
android:layout_width="140dp"
android:layout_height="120dp"
android:id="@+id/button5ExploreOne"
android:layout_alignTop="@+id/button6ExploreOne"
android:layout_toRightOf="@+id/button6ExploreOne"
android:layout_marginLeft="24dp"
android:background="#5865a2"
android:textColor="#ffffff"/>
<Button
android:layout_width="140dp"
android:layout_height="120dp"
android:id="@+id/button6ExploreOne"
android:layout_marginLeft="27dp"
android:layout_marginTop="410dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#cd4243"
android:textColor="#ffffff"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text=" What do want to explore?"
android:textColor="#00aeef"
android:id="@+id/textView"
android:layout_above="@+id/buttonExploreOne"
android:layout_alignLeft="@+id/buttonExploreOne"
android:layout_alignStart="@+id/buttonExploreOne"
android:layout_alignRight="@+id/button2ExploreOne"
android:layout_alignEnd="@+id/button2ExploreOne"
android:layout_marginBottom="44dp"
android:textSize="22sp" />
</RelativeLayout>
</ScrollView>