Не могу получить гравитацию на дно на "активность наложения" - PullRequest
0 голосов
/ 06 марта 2012

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

Я попробовал решения в этом вопросе: Отображение нового действия поверх предыдущего действия

Но это не сработало.

Так что, в принципе, я снова вернулся к этой простой схеме:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical" android:background="#000" android:weightSum="0.6">

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:background="@drawable/greybutton"
        android:text="text1"
        android:textColor="#FFF"
        android:textSize="18dp"
        android:textStyle="bold" />

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:background="@drawable/greybutton"
        android:text="text2"
        android:textColor="#FFF"
        android:textSize="18dp"
        android:textStyle="bold" />
</LinearLayout>

И в манифесте:

    <activity android:name=".Overlay_share" android:screenOrientation="portrait" android:theme="@style/Theme.Transparent"></activity>

И в моих стилях:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@color/semitransparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
<color name="semitransparent">#00000000</color> 
</resources>

Любая помощь будет высоко ценится.

1 Ответ

0 голосов
/ 06 марта 2012

Хорошо, вы можете сделать это с помощью линейного макета, но я бы предложил относительный.

  1. Измените match_parent на fill_parent для вашего макета
  2. Вам нужно указать android: gravity = "bottom" для кнопок индивидуально
  3. Если вам нужно, чтобы кнопки имели одинаковый вес, вы должны добавить еще один LinearLayout, который оборачивает кнопки и задает weightSum, и для кнопок указывается индивидуальный layout_weight для кнопок.

Итак fill_parent , вложенный LinearLayout для кнопок, который задает weightSum и использует wrap_content , и задает layout_weight для отдельного человека кнопок. Или RelativeLayout, как я попытаюсь продемонстрировать ниже.

Вот как я бы предложил (лично)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:background="#000">

<RelativeLayout
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_alignParentBottom="true"
    android:paddingBottom="20dp"
    android:paddingRight="30dp"
    android:paddingLeft="30dp>
<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="40dp"
    android:paddingRight="10dp"
    android:background="@drawable/greybutton"
    android:text="text1"
    android:textColor="#FFF"
    android:textSize="18dp"
    android:textStyle="bold" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="40dp"
    android:paddingLeft="10dp"
    android:layout_toRightOf="@id/button1"
    android:background="@drawable/greybutton"
    android:text="text2"
    android:textColor="#FFF"
    android:textSize="18dp"
    android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>

или LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:background="#000">
<LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:gravity="bottom"
    android:weightSum="2"
    android:paddingBottom="20dp"
    android:paddingRight="30dp"
    android:paddingLeft="30dp>
<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="40dp"
    android:paddingRight="10dp"
    android:background="@drawable/greybutton"
    android:text="text1"
    android:layout_weight="1"
    android:textColor="#FFF"
    android:textSize="18dp"
    android:textStyle="bold" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="40dp"
    android:paddingLeft="10dp"
    android:layout_weight="1"
    android:background="@drawable/greybutton"
    android:text="text2"
    android:textColor="#FFF"
    android:textSize="18dp"
    android:textStyle="bold" />
</LinearLayout>
</LinearLayout>

Надеюсь, это как минимум выведет вас на правильный путь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...