2013-04-10 48 views
0

此元素的设置重力是XML代码:Android的 - 在XML

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

<RelativeLayout 
     android:id="@+id/relative_layout_main" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 

    <com.adsdk.sdk.banner.AdView 
     android:id="@+id/ad_1" 
     android:layout_width="300dp" 
     android:background="#000000" 
     android:layout_height="50dp" 
     request_url="http://my.mobfox.com/request.php" 
     publisherId="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 
     android:layout_centerHorizontal="true" 
     android:gravity="center" 
     location="true" 
     animation="true" /> 

    <TextView 
     android:textIsSelectable="true" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="center" 
     android:textStyle="bold" 
     android:id="@+id/error_view_2" 
     android:layout_marginTop="20dp" 
    android:layout_below="@id/ad_1" 
     android:text="@string/gen_mess_err" />  

    <TextView 
     android:textIsSelectable="true" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="center" 
     android:layout_below="@id/error_view_2" 
     android:id="@+id/error_view_1" /> 

    <com.adsdk.sdk.banner.AdView 
     android:id="@+id/ad_2" 
     android:layout_width="300dp" 
     android:background="#000000" 
     android:layout_height="50dp" 
     request_url="http://my.mobfox.com/request.php" 
     publisherId="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="20dp" 
     android:layout_below="@id/error_view_1" 
     android:gravity="bottom" 
     location="true" 
     animation="true" /> 

</RelativeLayout> 

我要的是设置广告一个在顶部,一个在屏幕上的钮,和屏幕中央的textview,但这不起作用。我能怎么做?

THX提前:)

回答

1

更改您的XML代码到这个

android:fillViewport must be set to true - 如果设置为true,此属性将导致滚动视图的孩子,如果需要扩展到了滚动的高度。当孩子比ScrollView高时,该属性不起作用。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fillViewport="true" > 
<RelativeLayout 
    android:id="@+id/relative_layout_main" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
    <com.adsdk.sdk.banner.AdView 
     android:id="@+id/ad_1" 
     android:layout_width="300dp" 
     android:layout_height="50dp" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     animation="true" 
     location="true" 
     publisherId="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 
     request_url="http://my.mobfox.com/request.php" 
     android:background="#000000" 
     android:gravity="center" /> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:orientation="vertical" > 
     <TextView 
      android:id="@+id/error_view_2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dp" 
      android:gravity="center" 
      android:text="@string/gen_mess_err" 
      android:textIsSelectable="true" 
      android:textStyle="bold" /> 
     <TextView 
      android:id="@+id/error_view_1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:textIsSelectable="true" /> 
    </LinearLayout> 
    <com.adsdk.sdk.banner.AdView 
     android:id="@+id/ad_2" 
     android:layout_width="300dp" 
     android:layout_height="50dp" 
     android:layout_alignParentBottom="true" 
     android:layout_below="@id/error_view_1" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="20dp" 
     animation="true" 
     location="true" 
     publisherId="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 
     request_url="http://my.mobfox.com/request.php" 
     android:background="#000000" 
     android:gravity="bottom" /> 
</RelativeLayout> 

+0

感谢,它的工作原理:)不过我试图使用Android:layout_alignParentBottom =“真”在我的代码,并修改它worls过一些参数,谢谢反正:) – Gimmy88 2013-04-10 14:25:56

1

为什么ScrollView设置为wrap_contentlayout_height属性?它应该是match_parent为了填满屏幕,以便广告放置在顶部和底部。

此外,物业fill_parent过时,match_parent是其新的价值:)

0

你的这个

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    > 
    <com.adsdk.sdk.banner.AdView 
      android:id="@+id/ad_1" 
      android:layout_width="fill_parent" 
      android:background="#000000" 
      android:layout_height="wrap_content" 
      request_url="http://my.mobfox.com/request.php" 
      publisherId="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 
      android:layout_centerHorizontal="true" 
      android:gravity="center" 
      location="true" 
      animation="true" /> 

    <ScrollView 
      android:id="@+id/relative_layout_main" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      > 

    <TextView 
      android:textIsSelectable="true" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:gravity="center" 
      android:textStyle="bold" 
      android:id="@+id/error_view_2" 
      android:layout_marginTop="20dp" 
      android:text="string/gen_mess_err" /> 

    <TextView 
      android:textIsSelectable="true" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:gravity="center" 
      android:id="@+id/error_view_1" /> 
    </ScrollView> 

    <com.adsdk.sdk.banner.AdView 
      android:id="@+id/ad_2" 
      android:layout_width="fill_parent" 
      android:background="#000000" 
      android:layout_height="wrap_content" 
      request_url="http://my.mobfox.com/request.php" 
      publisherId="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 
      android:layout_marginTop="-51dp" 
      android:gravity="bottom" 
      location="true" 
      animation="true" 
      /> 

希望它的帮助。