【问题标题】:How to make high score list in android如何在android中制作高分榜
【发布时间】:2014-05-03 16:10:31
【问题描述】:

我正在制作小型安卓游戏。而且我在项目结束时遇到了麻烦,我不知道如何制作高分榜。

我想用

列出清单

第一点

第二点

第 3 点

我尝试使用 SharedPreferences。我的代码:

SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(final_hard_android.this);
    Editor editor = sp.edit();
    editor.putString("username", "<username goes here>");
    editor.putInt("score", point);
    editor.commit();
    String gameUsername = sp.getString("username", "default");
    int gameScore = sp.getInt("score", 0);

积分是游戏的结果!

但我不明白,也不知道如何在图层上显示此列表?

请帮忙。

欣赏

【问题讨论】:

    标签: java android listview android-listview sharedpreferences


    【解决方案1】:

    真的!! 您可以使用带有 6 个标签的布局(用于显示点和排名)

        <?xml version="1.0" encoding="utf-8"?>
    
    
       <RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"    
        >
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="24dp"
            android:layout_marginTop="37dp"
            android:text="1ST" />
    
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/textView1"
            android:layout_centerHorizontal="true"
            android:text="Points"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView1"
            android:layout_below="@+id/textView2"
            android:layout_marginTop="34dp"
            android:text="2ND" />
    
        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView2"
            android:layout_alignTop="@+id/textView3"
            android:layout_marginLeft="14dp"
            android:text="Points"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView3"
            android:layout_below="@+id/textView4"
            android:layout_marginTop="34dp"
            android:text="3RD" />
    
        <TextView
            android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView4"
            android:layout_alignTop="@+id/textView5"
            android:text="Points"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
    </RelativeLayout>
    

    并在活动中调用您的布局,例如:

    setContentView(R.layout.test);
    TextView lbl1 = (TextView)findViewById(R.id.textView2);
    lbl1.setText("1st your point");
    
    TextView lbl2 = (TextView)findViewById(R.id.textView4);
    lbl2.setText("2nd your point");
    
    TextView lbl3 = (TextView)findViewById(R.id.textView6);
    lbl3.setText("3rd your point");
    

    【讨论】:

    • 你不懂-.-我需要java代码..我应该用xml做什么..我知道如何制作xml
    猜你喜欢
    • 2023-04-05
    • 2021-03-03
    • 2016-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多