2014-09-19 99 views
0

因此,我有一個作爲對話框(Theme.Dialog)啓動的活動。我用它來播放視頻,調暗背景,看起來很酷......但它總是集中在屏幕上,不知道如何以編程方式將其移動到底部。如何將ViewGroup與屏幕底部對齊

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/lr_layout" 
      android:background="#FF000000" 
      android:padding="0dp" > 


<RelativeLayout 
    android:id="@+id/lr_progressContainer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FF000000"> 

    <ProgressBar android:id="@+id/lr_progress" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:background="@android:color/black" 
     style="@android:style/Widget.ProgressBar.Large" /> 

    <View android:id="@+id/disableShape" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="0dp" 
    android:visibility="gone" 
    android:background="#CC000000" 
    /> 
</RelativeLayout> 

</RelativeLayout> 

然後我以編程方式添加視頻播放器(從第三方查看)。

我已經試過這樣:

layout = (ViewGroup) findViewById(R.id.lr_layout); 
layout.setY(0); 

這:

RelativeLayout.LayoutParams adViewLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); 
adViewLayoutParams.addRule(RelativeLayout.ALIGN_BOTTOM); 
layout.addView(adView, adViewLayoutParams); 

但視頻仍然在該中心。

有什麼想法?

謝謝!

回答

1

試着把它放在你的onCreate方法中。

WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.gravity = Gravity.BOTTOM; getWindow().set attributes(lp);

+0

工程就像一個魅力。感謝西蒙! – vanderflo 2014-09-19 21:11:36

0

如果你想將relativeLayout子對象放在底部,你可以設置alignParentBottom = true 如果你想將對話框對齊屏幕底部,你可以使用popupWindow代替!