user3391693 user3391693 - 1 month ago 14
Android Question

Android Layout components alignment Issue

Hi I am trying to align few buttons and a webview with admob ads. But the alignment which i required is not I am getting.

Here is my code

the attached screen shot is the layout I need.

<?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>


what i am doing wrong?layout sample

Answer

Solution:

 <?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">


    </WebView>

</RelativeLayout>