Проблема выравнивания компонентов макета Android

#android #android-studio

#Android #android-studio

Вопрос:

Привет, я пытаюсь выровнять несколько кнопок и веб-просмотр с рекламой admob. Но выравнивание, которое мне требовалось, я не получаю.

Вот мой код

прилагаемый снимок экрана — это макет, который мне нужен.

 <?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.profilephotos.dp.MainActivity"
    tools:showIn="@layout/activity_view_image">
    <com.google.android.gms.ads.AdView
        android:background="@color/adbackcolor"
        android:id="@ id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id">
    </com.google.android.gms.ads.AdView>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:paddingBottom="@dimen/activity_vertical_margin">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true">

                <TableRow>
                    <WebView
                        android:id="@ id/webViewimage"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#8a0707"
                        android:layout_marginBottom="110dp"
                        android:layout_marginTop="0dp"
                        android:layout_marginLeft="0dp"
                        android:layout_marginRight="0dp"
                        />
                </TableRow>
                <TableRow android:layout_height="match_parent">

                    <Button
                        android:id="@ id/btnsaveimage"
                        android:layout_width="wrap_content"
                        android:layout_height="56dp"
                        android:layout_marginBottom ="5dp"
                        android:layout_weight="1"
                        android:text="Save"
                        android:onClick="triggeractionbtnclick"
                        android:layout_above="@ id/adView" />

                    <Button
                        android:id="@ id/btnshareimage"
                        android:layout_width="wrap_content"
                        android:layout_height="56dp"
                        android:layout_marginBottom ="5dp"
                        android:layout_weight="1"
                        android:text="Share"
                        android:onClick="triggeractionbtnclick"
                        android:layout_above="@ id/adView" />

                    <Button
                        android:id="@ id/btnsetas"
                        android:layout_width="wrap_content"
                        android:layout_height="56dp"
                        android:layout_marginBottom ="5dp"
                        android:layout_weight="1"
                        android:text="Set As"
                        android:onClick="triggeractionbtnclick"
                        android:layout_above="@ id/adView"/>

                </TableRow>

            </TableLayout>

        </LinearLayout>

    </LinearLayout>


</RelativeLayout>
  

что я делаю не так?образец макета

Ответ №1:

Решение:

  <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout 
       xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:tools="http://schemas.android.com/tools"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       xmlns:ads="http://schemas.android.com/apk/res-auto">

    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:id="@ id/toolbar"
        android:background="@color/colorPrimary"
        android:layout_height="wrap_content">

    </android.support.v7.widget.Toolbar>

    <com.google.android.gms.ads.AdView
        android:id="@ id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        android:layout_alignParentBottom="true"
        ads:adUnitId="@string/banner_home_footer">
    </com.google.android.gms.ads.AdView>


    <TableLayout
        android:layout_width="match_parent"
        android:layout_above="@ id/adView"
        android:id="@ id/table"
        android:layout_height="wrap_content">

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <Button android:layout_width="wrap_content"
                android:layout_weight="1"
                android:text="Button 1"
                android:layout_height="wrap_content"/>

            <Button android:layout_width="wrap_content"
                android:layout_weight="1"
                android:text="Button 2"
                android:layout_height="wrap_content"/>

            <Button android:layout_width="wrap_content"
                android:layout_weight="1"
                android:text="Button 3"
                android:layout_height="wrap_content"/>
        </TableRow>

    </TableLayout>


    <WebView
        android:layout_width="match_parent"
        android:layout_below="@ id/toolbar"
        android:id="@ id/webview"
        android:layout_above="@ id/table"
        android:layout_height="match_parent"/>

</RelativeLayout>
  

Комментарии:

1. не добавляйте только решение, добавьте, почему это произошло, и соответствующую ссылку.

Ответ №2:

Таким образом, вы можете добиться этого, как будто я просто изложу ваши взгляды.

 <RelativeLayout

    <WebView
      height="match_parent"
      widht="match_parent" 
      id="webview1"/>

    <LinearLayout
     layout_above="@id/webview1"
     align_parent_bottom="true"
     orientation="vertical"

         <LinearLayout weight_sum=3
             orientation="horizontal">

               <Buttion width=0"
                   weight=1 />

              <Buttion width=0"
                   weight=1 />

              <Buttion width=0"
                   weight=1 />

         </LinearLayout>  

         <AdMobView />

     </LinearLayout>

</RelativeLayout>
  

Грубая идея, но она решит вашу проблему.