答案 0 :(得分:6)
您需要设计另一个布局,仅显示弹出窗口并使其成为alignparenttop。这是示例布局
创建新的xml文件dialog.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLyt"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#FFFFFF"
android:paddingTop="10dp" >
<TextView
android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Fill in your design in this place"
android:textSize="10dp" />
</RelativeLayout>
</RelativeLayout>
创建设计后。你需要在你的onbutton点击中调用它。以下是显示对话的示例
ratingButton.setOnCLickListener(new view.OnCLickListener(){
@Override
public void onCLick(View v){
final Dialog fbDialogue = new Dialog(ProfileActivity.this, android.R.style.Theme_Black_NoTitleBar);
fbDialogue.getWindow().setBackgroundDrawable(new ColorDrawable(Color.argb(100, 0, 0, 0)));
fbDialogue.setContentView(R.layout.facebook_dialogue);
fbDialogue.setCancelable(true);
fbDialogue.show();
}
});
Hey I have put the code in onclicklistener. Check it . The above code works perfectly fine for me. As per my requirement I wanted the dialogue on the bottom of the screen . I have just made few lines of code change above to meet your requirement. My requirement was something like this
答案 1 :(得分:-1)
您可以将其实现为当前布局的叠加层。它可能因实现而异。
我使用以下方法实现了这个:
<RelativeLayout> <- This is the parent
<RelativeLayout id="actual_layout"> <- This is where you will implement the layout
<!--Implement your layout here-->
</RelativeLayout>
<RelativeLayout id="rating_container"
visibility="gone"
background="#BB000000"> <- This is to set the translucent black background
<RelativeLayout id="rating_dialog"
alignParnetTop="true"> <- This is the rating dialog
<!--Your implementation here-->
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
现在,在“评级”按钮的onCLick中切换“rating_container”的可见性。
ratingButton.setOnCLickListener(new view.OnCLickListener(){
@Override
public void onCLick(View v){
toggleRatingContainer(true);
}
});
您可以按照此方法实施您的要求。如果您需要更多帮助,请告诉我。
注意:我还没有写完整的代码。此外,我没有检查,但直接键入一切。
修改强>:
您可以像下面这样实现toggleRatingContainer:
public void toggleRatingContainer(boolean showRatingDialog){
ratingContainer.setVisibility((showRatingDialog)?View.VISIBLE:View.GONE);
}
这里,“ratingContainer”是ID为“rating_container”的“RelativeLayout”,你可以在你的活动的onCreate方法中获得它。
然后,当点击“提交”或“取消”按钮时,通过调用传递“false”作为参数的相同方法,可以将其可见性切换为“View.GONE”。