开发者

How can I set a layout_Above with 2 values?

Right now, I have a layout that looks like one of the two images below, depending on the exact size of the screen. Bot that on one, the Play Game! button is on top, and on the other, the copyright text is on top.

How can I set a layout_Above with 2 values?

How can I set a layout_Above with 2 values?

What I'm trying to do is to put an image between the adview and the higher of the top text box/layout. Depending on different screen sizes, the entry that's on top can vary. I would like to not have this problem a开发者_Go百科t all... I know how to put it below the imageview, but not put it above both items.

So far, I've tried a relativeLayout that encloses the bottom variables, and told the image to be above that, but below the AdView. Problem is, the top of the RelativeView goes clear to the top, despite it being set to wrap_content and none of the below values go that high.

I've also considered aligning either the top of the text to the top of the button, or visa versa, but I'm seeing a potentially ugly interface in my mind, one in which the top button might be bigger, or part of the copyright text obscured.

So, I'm looking for one of two solutions. A way to tell my image to be above 2 items, the button and the text, or some way to wrap the context such that I can just be above the wrapped value.

Here's the relevant XML code I've tested.

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" 
  android:orientation="vertical">
  <com.google.ads.AdView android:id="@+id/adView" ads:loadAdOnCreate="true" ads:adSize="BANNER" ads:adUnitId="@string/admob_unit_id" android:layout_width="wrap_content" android:layout_height="wrap_content" ></com.google.ads.AdView>
  <ImageView android:src="@drawable/start_logo" android:gravity="center" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/logo_view" android:layout_below="@+id/adView" android:layout_above="@+id/buttons_copyright"></ImageView>
  <RelativeLayout android:id="@+id/buttons_copyright" android:layout_width="fill_parent" android:layout_alignParentLeft="true" android:layout_alignParentBottom="true"  android:layout_alignParentTop="false" android:layout_height="wrap_content">
   (NOTE: LOTS OF STUFF GOES HERE)
  </RelativeLayout>
</RelativeLayout>


I've made a layout that will work for you - it looks like this: Edit: Try this one...

How can I set a layout_Above with 2 values?

Use this layout (replace the top button with your ad) (changed a bit since last edit to use anther relative layout...)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button
        android:text="Button"
        android:id="@+id/button1"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"></Button>
    <TextView
        android:text="Version Text"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_alignBaseline="@+id/instructions_button"
        android:layout_toLeftOf="@+id/instructions_button"
        android:layout_marginLeft="5dp" />
    <Button
        android:id="@+id/instructions_button"
        android:layout_width="wrap_content"
        android:text="Instructions"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:minWidth="100dp"
        android:layout_alignParentBottom="true" />
    <TextView
        android:text="Game Name Text"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_alignBaseline="@+id/scores_button"
        android:layout_toLeftOf="@+id/scores_button"
        android:layout_marginLeft="5dp" />
    <Button
        android:id="@+id/scores_button"
        android:layout_width="wrap_content"
        android:text="High Scores"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:minWidth="100dp"
        android:layout_above="@+id/instructions_button" />
    <RelativeLayout
        android:id="@+id/copyright_layout"
        android:layout_above="@+id/scores_button"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent">
        <TextView
            android:text="Copyright text goes here and goes on and on a bit and fills up a few lines and looks ok generally and keeps on going and going and going and going onto many lines longer thatn it should etct"
            android:textSize="10sp"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:layout_alignTop="@+id/play_button"
            android:layout_toLeftOf="@+id/play_button"
            android:layout_marginLeft="5dp" />
        <Button
            android:id="@+id/play_button"
            android:layout_width="wrap_content"
            android:text="Play Game!"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:minWidth="100dp"
            android:layout_above="@+id/scores_button" />
    </RelativeLayout>
    <ImageView
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:id="@+id/imageView1"
        android:layout_margin="5dp"
        android:layout_above="@+id/copyright_layout"
        android:layout_below="@+id/button1"
        android:src="@drawable/map"
        android:scaleType="centerCrop" />
</RelativeLayout>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜