我试图将带有文本的切换按钮放在ImageView旁边。 另外,在Switch上方和同一ImageView旁边应该有几个其他TextView。
首先,我尝试将Switch放入FrameLayout中,然后将其移至右侧,以便在左侧留有ImageView的空间。但是结果是我不能将ImageView放在那儿。 ImageView是父级LinearLayout的一部分。 预习: 和代码:
<ImageView
android:id="@+id/event_image"
android:layout_width="125dp"
android:layout_height="120dp"
android:layout_gravity="start"
android:scaleType="fitXY" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@color/ToggleColor"
android:gravity="end"
android:orientation="vertical">
<Switch
android:id="@+id/switch1"
android:layout_width="276dp"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:text="Recieve emails about upcoming events at this club."
android:textColor="@color/white"
android:textSize="14dp"
android:textStyle="normal" />
</FrameLayout>
然后,我摆脱了FrameLayout,将ImageLayout并切换到单独的LinearLayout。 已更新。 我在里面添加了另一个linearLayout。看起来更接近目标,但边界并不完美。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/event_image"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="start"
android:scaleType="fitXY" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/event_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Event Name"
android:textColor="@color/white" />
<TextView
android:id="@+id/club_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Club Name"
android:textColor="@color/white" />
<TextView
android:id="@+id/date_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Date"
android:textColor="@color/white"
android:paddingBottom="11dp"/>
<Switch
android:onClick="switch_handler"
android:id="@+id/switch1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="5dp"
android:background="@color/ToggleColor"
android:paddingLeft="10dp"
android:text="Recieve emails about upcoming events at this club."
android:textColor="@color/white"
android:textSize="14dp"
android:textStyle="normal" />
</LinearLayout>
</LinearLayout>
我希望此开关元素位于手机底部的黑色边框旁边和电话的右边框旁边。