我正在制作一个简单的游戏,当游戏结束时,它会显示一个带有播放按钮的自定义对话框(重新开始游戏),一个带有得分的TextView,另一个带有最高分的,最后一个选择游戏的微调器下次很难。对话框应如下所示:
但是当我尝试对话框时,它显示如下:
对于发生了什么事情的任何想法?,我一直试图把它放在许多不同的位置,但仍然显示不同......
对话框的代码是:
public void pulsar(View v){
final Dialog try_again = new Dialog(this);
try_again.requestWindowFeature(Window.FEATURE_NO_TITLE);
try_again.setCancelable(false);
try_again.setContentView(R.layout.try_again);
TextView SCORE = (TextView)try_again.findViewById(R.id.score);
SCORE.setText(SCORE.getText().toString() + "80");//for example
TextView BEST = (TextView)try_again.findViewById(R.id.best);
BEST.setText(BEST.getText().toString() + "90");//for example
Spinner sp = (Spinner)try_again.findViewById(R.id.sp);
sp.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,new String[]{"easy","normal","difficult"}));//for exmaple
try_again.findViewById(R.id.play).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
recreate();
try_again.dismiss();
}
});
try_again.show();
}
并从对话框的xml文件中:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/background">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/play"
android:background="@drawable/background"
android:focusable="true"
android:src="@drawable/play"
android:layout_gravity="center_horizontal"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="SCORE : "
android:id="@+id/score"
android:textColor="#ff989898"
android:textStyle="bold"
android:gravity="center"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/play"
android:layout_toStartOf="@+id/play"
android:minWidth="@dimen/abc_button_inset_vertical_material" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="BEST : "
android:id="@+id/best"
android:textColor="#ff989898"
android:textStyle="bold"
android:gravity="center"
android:layout_alignTop="@+id/score"
android:layout_toRightOf="@+id/play"
android:layout_toEndOf="@+id/play" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/sp"
android:spinnerMode="dropdown"
android:popupBackground="@drawable/background"
android:gravity="center"
android:layout_below="@+id/play"
android:layout_alignRight="@+id/best"
android:layout_alignEnd="@+id/best" />
答案 0 :(得分:0)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/background">
<LinearLayout
android:id="@+id/ll_map_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="SCORE : "
android:id="@+id/score"
android:textColor="#ff989898"
android:textStyle="bold"
android:minWidth="@dimen/abc_button_inset_vertical_material"
android:layout_weight="1"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/play"
android:background="@drawable/background"
android:focusable="true"
android:src="@drawable/play"
android:layout_weight="1"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="BEST : "
android:id="@+id/best"
android:textColor="#ff989898"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="1"
/>
</LinearLayout>
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/sp"
android:spinnerMode="dropdown"
android:popupBackground="@drawable/background"
android:gravity="center"
android:layout_below="@+id/ll_map_header"/>