2012-03-06 2 views
0

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

я попробовал решения в этом вопросе: Display new Activity on top of previous Activity

Но это не делать.

Поэтому в основном я до этой простой макет снова:

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

Любая помощь будем очень благодарны.

ответ

0

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

  1. Изменить match_parent в fill_parent для макета
  2. Вы должны указать андроида: плотность = «низ» для кнопок по отдельности
  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> 

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

+0

Используя RelativeLayout с LinearLayout внутри, сделал трюк без особых хлопот! Так что ваш первый комментарий действительно был самым простым: o), спасибо! –