一、前言
铁大树洞对于我来说目前主要的任务是前端UI界面的设计,今天在前几天的基础上对整体页面进行了改动,学习了Fragment的使用底部导航栏,实现了整框架的页面,完成了加载页面、logo以及部分图标的设计工作,为了让APP更加的美观,尝试着从网上找了一些小功能,但效果不是特别理想。
明天对UI界面进行进一步的优化,对每个页面上的细节进行设计与调整配色。
二、成果展示
三、代码
MainActivity.java
package com.example.tiedashudong.Activity; import android.content.Intent; import android.os.Bundle; import android.util.SparseArray; import android.view.View; import android.view.WindowManager; import android.widget.RadioGroup; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import com.example.tiedashudong.R; import com.example.tiedashudong.fragment.Fragment_Index; import com.example.tiedashudong.fragment.Fragment_My; import com.example.tiedashudong.fragment.Fragment_Star; import com.example.tiedashudong.fragment.Fragment_Three; public class MainActivity extends AppCompatActivity { private RadioGroup mTabRadioGroup; private SparseArray<Fragment> mFragmentSparseArray; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //去掉顶部标题 getSupportActionBar().hide(); //去掉最上面时间、电量等 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN , WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); initView(); } private void initView() { mTabRadioGroup = findViewById(R.id.tabs_rg); mFragmentSparseArray = new SparseArray<>(); mFragmentSparseArray.append(R.id.index_tab, Fragment_Index.newInstance("主页")); mFragmentSparseArray.append(R.id.star_tab, new Fragment_Star()); mFragmentSparseArray.append(R.id.contact_tab, Fragment_Three.newInstance("待定")); mFragmentSparseArray.append(R.id.my_tab, new Fragment_My()); mTabRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // 具体的fragment切换逻辑可以根据应用调整,例如使用show()/hide() getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, mFragmentSparseArray.get(checkedId)).commit(); } }); // 默认显示第一个 getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, mFragmentSparseArray.get(R.id.index_tab)).commit(); findViewById(R.id.sign_iv).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(MainActivity.this, SendActivity.class)); } }); } }
Fragment_Index.java
package com.example.tiedashudong.fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import androidx.fragment.app.Fragment; import com.example.tiedashudong.R; public class Fragment_Index extends Fragment { // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private static final String ARG_SHOW_TEXT = "text"; private String mContentText; public Fragment_Index() { // Required empty public constructor } public static Fragment_Index newInstance(String param1) { Fragment_Index fragment = new Fragment_Index(); Bundle args = new Bundle(); args.putString(ARG_SHOW_TEXT, param1); fragment.setArguments(args); return fragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mContentText = getArguments().getString(ARG_SHOW_TEXT); } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_index, container, false); TextView contentTv = rootView.findViewById(R.id.content_tv); contentTv.setText(mContentText); return rootView; } }
Fragment_Star.java
package com.example.tiedashudong.fragment; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.fragment.app.Fragment; import com.example.tiedashudong.R; public class Fragment_Star extends Fragment implements SensorEventListener { public Fragment_Star() { // Required empty public constructor } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_star, container, false); return rootView; } @Override public void onSensorChanged(SensorEvent sensorEvent) { } @Override public void onAccuracyChanged(Sensor sensor, int i) { } }
Fragment_Three.java
package com.example.tiedashudong.fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import androidx.fragment.app.Fragment; import com.example.tiedashudong.R; public class Fragment_Three extends Fragment { // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private static final String ARG_SHOW_TEXT = "text"; private String mContentText; public Fragment_Three() { // Required empty public constructor } public static Fragment newInstance(String param1) { Fragment_Three fragment = new Fragment_Three(); Bundle args = new Bundle(); args.putString(ARG_SHOW_TEXT, param1); fragment.setArguments(args); return fragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mContentText = getArguments().getString(ARG_SHOW_TEXT); } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_three, container, false); TextView contentTv = rootView.findViewById(R.id.content_tv); contentTv.setText(mContentText); return rootView; } }
Fragment_My.java
package com.example.tiedashudong.fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.fragment.app.Fragment; import com.example.tiedashudong.R; public class Fragment_My extends Fragment { // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private static final String ARG_SHOW_TEXT = "text"; private String mContentText; public Fragment_My() { // Required empty public constructor } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_my, container, false); return rootView; } }
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Activity.MainActivity"> <FrameLayout android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/tabs_rg" /> <RadioGroup android:id="@+id/tabs_rg" android:layout_width="match_parent" android:layout_height="56dp" android:layout_alignParentBottom="true" android:background="#dcdcdc" android:orientation="horizontal"> <RadioButton android:id="@+id/index_tab" style="@style/Custom.TabRadioButton" android:checked="true" android:drawableTop="@drawable/tab_sign_selector" android:text="首页" /> <RadioButton android:id="@+id/star_tab" style="@style/Custom.TabRadioButton" android:drawableTop="@drawable/tab_record_selector" android:text="星球" /> <View style="@style/Custom.TabRadioButton" /> <RadioButton android:id="@+id/contact_tab" style="@style/Custom.TabRadioButton" android:drawableTop="@drawable/tab_contact_selector" android:text="?" /> <RadioButton android:id="@+id/my_tab" style="@style/Custom.TabRadioButton" android:drawableTop="@drawable/tab_setting_selector" android:text="我" /> </RadioGroup> <ImageView android:id="@+id/sign_iv" android:layout_width="80dp" android:layout_height="80dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:background="@android:color/transparent" android:src="@mipmap/sign" /> </RelativeLayout>
四、今日团队链接