【发布时间】:2014-01-04 20:22:38
【问题描述】:
我已经设置了一个 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>
【问题讨论】: