叶哈哈哈哈叶

巨鲸落,万物生。

放弃不难,但坚持一定很酷。


一步一步完成猜歌游戏(三)

我们的游戏通关界面,首先是布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pass_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/index_background"
    android:orientation="vertical">

    <include layout="@layout/top_bar" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/allpass_back0"
        android:gravity="center">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/allpass_text0" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="5dp"
            android:background="@drawable/game_wx_text" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/game_coin_icon" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_weight="1"
        android:background="@drawable/allpass_back1"
        android:gravity="center">

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:background="@drawable/allpass_wechat_botton_icon" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="5dp"
            android:background="@drawable/about_rank_text" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/game_coin_icon" />
    </LinearLayout>

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_weight="1"
        android:background="@drawable/allpass_back1">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@drawable/allpass_text2" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:background="@drawable/rank_botton_icon" />

    </FrameLayout>

</LinearLayout>

具体效果:

逻辑代码:

public class AppPassView extends Activity {

    private ImageButton back_button_icon;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.all_pass_view);

        //隐藏右上角的金币按钮
        FrameLayout view = findViewById(R.id.layout_bar_coin);
        view.setVisibility(View.INVISIBLE);

        back_button_icon = findViewById(R.id.back_botton_icon);
        back_button_icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Util.startActivity(AppPassView.this, MainActivity.class);
                finish();
            }
        });
    }
}

总结: 1、尽量避免硬编码,将需要使用的都定义为常量,提高代码可读性 2、将重复使用的代码封装为函数,通过调用,使得程序代码简洁明了 3、做好注释,一目了然

打赏一个呗

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦