FrameLayout или LinearLayout - PullRequest
       22

FrameLayout или LinearLayout

0 голосов
/ 03 января 2019

Я пытаюсь поместить мою кнопку переключателя с текстом рядом с ImageView.Кроме того, должно быть несколько других TextViews выше Коммутатора и рядом с тем же ImageView.

Сначала я попытался поместить Switch в FrameLayout, а затем переместил его вправо, чтобы слева оставалось место для ImageView.Но в результате я не могу поместить ImageView туда.ImageView является частью родительского LinearLayout.Предварительный просмотр: Preview with FrameLayout И код:

<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 и Switch в отдельную 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>

Я хочу, чтобы этот элемент переключателя находился рядом с черной рамкой внизу и рядом с правой границей телефона.

enter image description here

...