Как я могу установить layout_Above с 2 значениями? - PullRequest
0 голосов
/ 04 июня 2011

Прямо сейчас у меня есть макет, который выглядит как одно из двух изображений ниже, в зависимости от точного размера экрана. Бот, что на одном, Play Game! кнопка сверху, а с другой стороны, текст об авторском праве сверху.

enter image description here enter image description here

То, что я пытаюсь сделать, это поместить изображение между объявлением и верхним краем верхнего текстового поля / макета. В зависимости от размера экрана, запись сверху может отличаться. Я бы не хотел, чтобы эта проблема была вообще ... Я знаю, как разместить ее под изображением, но не поставить над обоими пунктами.

До сих пор я пробовал относительное расположение, которое содержит нижние переменные, и указывало, что изображение должно быть выше этого, но ниже AdView. Проблема в том, что вершина RelativeView становится прозрачной, несмотря на то, что для нее установлено значение wrap_content, и ни одно из приведенных ниже значений не достигает такого высокого уровня.

Я также подумал о выравнивании либо верхней части текста с верхней частью кнопки, либо наоборот, но я вижу потенциально уродливый интерфейс, в котором верхняя кнопка может быть больше, или часть текста об авторских правах скрыта.

Итак, я ищу одно из двух решений. Способ сказать, что мое изображение должно быть выше 2-х элементов, кнопка и текст, или какой-то способ обернуть контекст так, чтобы я мог просто быть выше обернутого значения.

Вот соответствующий код XML, который я тестировал.

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

1 Ответ

4 голосов
/ 04 июня 2011

Я сделал макет, который будет работать для вас - он выглядит следующим образом: Редактировать: Попробуйте это ...

enter image description here

Используйте этот макет (замените верхнюю частькнопка с вашим объявлением) (немного изменилась с момента последнего редактирования, чтобы использовать другой относительный макет ...)

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