在android中添加滚动视图底部的填充?
我想在这个滚动视图的底部添加填充,因为文本与我在底部的广告重叠。我对安卓开发相当陌生。我看了其他几篇文章,但似乎无法解决我的问题。谢谢 这是我的weddingfragment.xml在android中添加滚动视图底部的填充?,android,xml,scrollview,Android,Xml,Scrollview,我想在这个滚动视图的底部添加填充,因为文本与我在底部的广告重叠。我对安卓开发相当陌生。我看了其他几篇文章,但似乎无法解决我的问题。谢谢 这是我的weddingfragment.xml <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="false"
android:gravity="center"
android:scrollbars="horizontal" android:id="@+id/ScrollView">
<LinearLayout
android:layout_width="fill_parent"
android:orientation="vertical"
android:id="@+id/linearLayout2"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Formal or Black Tie"
android:layout_marginTop="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" • This means you should wear a Tuxedo or a dark colored suit."
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</ScrollView>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId=""
ads:adSize="BANNER"
ads:testDevices=""
ads:loadAdOnCreate="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
这是我的activity_main.xml,它是weddingfragment.xml的父级
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="false"
android:gravity="center"
android:scrollbars="horizontal" android:id="@+id/ScrollView">
<LinearLayout
android:layout_width="fill_parent"
android:orientation="vertical"
android:id="@+id/linearLayout2"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Formal or Black Tie"
android:layout_marginTop="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" • This means you should wear a Tuxedo or a dark colored suit."
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</ScrollView>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId=""
ads:adSize="BANNER"
ads:testDevices=""
ads:loadAdOnCreate="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
正如我在评论中所说,下面是一个XML示例,您可以使用它在运行时更改片段,并且仍然可以查看:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
<!-- Get a reference to this fragment and use the fragment .commit() to change it. See the API guides for more info. It must be a framelayout or you can't edit it. -->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frag_wedding_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId=""
ads:adSize="BANNER"
ads:testDevices=""
ads:loadAdOnCreate="true"
android:layout_alignParentBottom="true" />
</LinearLayout>
正如我在评论中所说,这里是一个XML示例,您可以使用它对片段进行运行时更改,并且仍然可以查看:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
<!-- Get a reference to this fragment and use the fragment .commit() to change it. See the API guides for more info. It must be a framelayout or you can't edit it. -->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frag_wedding_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId=""
ads:adSize="BANNER"
ads:testDevices=""
ads:loadAdOnCreate="true"
android:layout_alignParentBottom="true" />
</LinearLayout>
您应该能够添加scrollview,然后添加ads视图(如果它位于顶层容器的底部),不是吗?(我不知道你在哪里添加了weddingfragment,不确定你是通过代码还是通过片段添加的)查看我对你的代码的编辑(我刚刚在我的项目中加入了一个xml片段的副本):另外,当你发布到pastebin时,你应该删除你的adUnitId,这样别人就不会对它或其他东西进行垃圾邮件处理。这可能是坏的,如果他们要损害你的帐户的有效性。我是通过代码添加它,但我会尝试通过片段。谢谢你帮我澄清了这件事@Mgamerz感谢您捕捉到了这一点,如果您不需要在运行时对其进行更改,您可以将其保留为XML。如果您需要更改它,您必须以编程方式进行更改,因为您将无法正确获取对它的引用。那样的话。。。(我将发布我的示例代码作为答案)您应该能够添加scrollview,然后添加ads视图(如果它位于顶层容器的底部),不是吗?(我不知道你在哪里添加了weddingfragment,不确定你是通过代码还是通过片段添加的)查看我对你的代码的编辑(我刚刚在我的项目中加入了一个xml片段的副本):另外,当你发布到pastebin时,你应该删除你的adUnitId,这样别人就不会对它或其他东西进行垃圾邮件处理。这可能是坏的,如果他们要损害你的帐户的有效性。我是通过代码添加它,但我会尝试通过片段。谢谢你帮我澄清了这件事@Mgamerz感谢您捕捉到了这一点,如果您不需要在运行时对其进行更改,您可以将其保留为XML。如果您需要更改它,您必须以编程方式进行更改,因为您将无法正确获取对它的引用。那样的话。。。(我将发布示例代码作为答案)