我无法放置Adview
低于一个RecyclerView
。目前RecyclerView
占据了布局的其余部分并且Adview
没有显示。我在网上找到的解决方案都没有解决我的问题。通常layout_weight
or layout_below
解决了问题,但在本例中并非如此。
XML
<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"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#7c7c7c"
android:focusable="true"
android:focusableInTouchMode="true">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/relContainer"
android:background="@drawable/bordershadow2"
android:paddingBottom="17dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="10dp" />
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/recycler_view"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
<RelativeLayout
android:id="@+id/relContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bordershadow"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<TableLayout
android:id="@+id/purchaseTableLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="7dp"
android:paddingTop="7dp"
android:layout_alignParentTop="true"
android:stretchColumns="0,1,2">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="3">
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingLeft="2dp"
android:singleLine="true"
android:textColor="#000"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingLeft="2dp"
android:singleLine="true"
android:textColor="#000"
android:textSize="24sp"
android:textStyle="bold" />
<Spinner
android:id="@+id/typeSpinner"
style="style/Theme.Material"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:entries="@array/type_array"
android:textSize="@dimen/title_size" />
</TableRow>
</TableLayout>
<EditText
android:id="@+id/searchEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/purchaseTableLayout"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'() "
android:hint="Search"
android:imeOptions="actionDone"
android:singleLine="true" />
<TableLayout
android:id="@+id/tableLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/searchEditText"
android:paddingBottom="7dp"
android:paddingTop="7dp"
android:stretchColumns="0,1,2">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="3.0">
<Spinner
android:id="@+id/sortRaceSpinner"
style="style/Theme.Material"
android:paddingTop="5dp"
android:paddingBottom="10dp"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:entries="@array/sort_race_array"
android:textSize="@dimen/title_size" />
<Spinner
android:id="@+id/sortAffinitySpinner"
style="style/Theme.Material"
android:paddingTop="5dp"
android:paddingBottom="10dp"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:entries="@array/sort_affinity_array"
android:textSize="@dimen/title_size" />
<Spinner
android:id="@+id/sortSpinner"
style="style/Theme.Material"
android:paddingTop="5dp"
android:paddingBottom="10dp"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:entries="@array/sort_array"
android:textSize="@dimen/title_size" />
</TableRow>
</TableLayout>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
我有一个视图需要位于具有动态大小的回收器视图下。
这意味着视图应该随着 RecyclerView 的增长而向下移动。
我的解决方案是将 paddingBottom 添加到 RecyclerView,然后将负 marginTop 添加到视图中,效果非常好。
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:paddingBottom="48dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_marginTop="-48dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)