ฉันได้ตั้งค่า TableLayout และเพิ่มแถวเพื่อรวมปุ่มและ ImageView ImageView เป็นเพียงจุดสี ฉันเคยใช้สไตล์นี้กับ RelativeLayout มาก่อนและวางตำแหน่ง ImageView ไว้เหนือรูปภาพปุ่ม แอพใหม่ที่ฉันกำลังทำอยู่ใช้ TableLayout แต่เมื่อฉันพยายามตั้งค่าปุ่มด้วย ImageView มันจะไม่อนุญาตให้วางตำแหน่ง ตัวเลือกนี้ใช้กับ TableLayout ไม่ได้ใช่ไหม
<TableLayout
android:id="@+id/TB1"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<Button
android:id="@+id/Scene1"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="@drawable/custom_scene_buttons"
android:text="Scene 1"
android:textColor="@drawable/white"
android:textSize="20sp" />
<ImageView
android:id="@+id/colordot1"
android:layout_width="21dp"
android:layout_height="21dp"
android:background="@drawable/circle" />
</TableRow>
นี่คือโค้ดสำหรับเปลี่ยนสีจุด
Resources res = getResources();
final Drawable drawable = res.getDrawable(R.drawable.circle);
drawable.setColorFilter(Color.rgb(i, j, k), Mode.SRC_ATOP);
ImageView img = (ImageView) findViewById(R.id.colordot1);
img.setBackgroundDrawable(drawable);
นี่คือตัวเลือกเค้าโครงเชิงเส้นที่ฉันลอง
<LinearLayout android:orientation="vertical" >
<Button
android:id="@+id/Scene1"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="@drawable/custom_scene_buttons"
android:drawableRight="@drawable/circle"
android:text="Scene 1"
android:textColor="@drawable/white"
android:textSize="20sp" />
<ImageView
android:id="@+id/colordot1"
android:layout_width="21dp"
android:layout_height="21dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/circle" />
</LinearLayout>