Browse Source

feat: 布局完成

dev-calendar-view
niushuai233 1 year ago
parent
commit
3bed53c2aa
  1. 8
      app/build.gradle
  2. 14
      app/src/main/java/cc/niushuai/didicheck/ui/main/home/HomeFragment.java
  3. 19
      app/src/main/res/layout/fragment_home.xml

8
app/build.gradle

@ -32,8 +32,8 @@ android {
} }
} }
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_17
} }
buildFeatures { buildFeatures {
viewBinding true viewBinding true
@ -47,7 +47,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
implementation 'androidx.recyclerview:recyclerview:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.3.2'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
@ -58,7 +58,7 @@ dependencies {
// room持久化库 // room持久化库
def room_version = "2.5.0" def room_version = '2.6.1'
implementation "androidx.room:room-runtime:$room_version" implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version" annotationProcessor "androidx.room:room-compiler:$room_version"
// room分页组件 // room分页组件

14
app/src/main/java/cc/niushuai/didicheck/ui/main/home/HomeFragment.java

@ -2,6 +2,7 @@ package cc.niushuai.didicheck.ui.main.home;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -50,16 +51,15 @@ public class HomeFragment extends Fragment {
ConstraintLayout rootLayout = fragmentHomeBinding.getRoot(); ConstraintLayout rootLayout = fragmentHomeBinding.getRoot();
TextView homeTitleTextView = fragmentHomeBinding.homeTitleTextView; TextView homeTitleTextView = fragmentHomeBinding.homeTitleTextView;
homeTitleTextView.setGravity(Gravity.CENTER);
homeViewModel.getTitle().observe(getViewLifecycleOwner(), value -> homeTitleTextView.setText(value)); homeViewModel.getTitle().observe(getViewLifecycleOwner(), value -> homeTitleTextView.setText(value));
homeTitleTextView.setText("未完待续...");
CalendarView homeMainCalendar = fragmentHomeBinding.homeMainCalendar; CalendarView homeMainCalendar = fragmentHomeBinding.homeMainCalendar;
homeMainCalendar.setDate(DateUtil.offsetDay(new Date(), -10).getTime()); homeMainCalendar.setDate(DateUtil.date().getTime());
homeViewModel.getSelectDate().observe(getViewLifecycleOwner(), new Observer<Date>() { homeMainCalendar.setOnDateChangeListener((calendarView, year, month, day) -> {
@Override long date = calendarView.getDate();
public void onChanged(Date value) { Log.d("tagxx", "tag = " + DateUtil.date(date).toDateStr());
homeMainCalendar.setDate(DateUtil.millisecond(value));
Log.d(this.getClass().getSimpleName(), "set date to " + value);
}
}); });
RecyclerView homeDataZoneRecyclerView = fragmentHomeBinding.homeDataZoneRecyclerView; RecyclerView homeDataZoneRecyclerView = fragmentHomeBinding.homeDataZoneRecyclerView;

19
app/src/main/res/layout/fragment_home.xml

@ -11,21 +11,28 @@
<TextView <TextView
android:id="@+id/home_title_textView" android:id="@+id/home_title_textView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="0dp"
app:layout_constraintTop_toTopOf="@id/HomeFragmentRootLayout" /> app:layout_constraintHeight_percent="0.05"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!--日历组件view--> <!--日历组件view-->
<CalendarView <CalendarView
android:id="@+id/home_main_calendar" android:id="@+id/home_main_calendar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="0dp"
app:layout_constraintTop_toTopOf="@id/home_title_textView" /> app:layout_constraintHeight_percent="0.45"
app:layout_constraintLeft_toLeftOf="@id/home_title_textView"
app:layout_constraintTop_toBottomOf="@id/home_title_textView" />
<!--数据展示view--> <!--数据展示view-->
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/home_dataZone_recyclerView" android:id="@+id/home_dataZone_recyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="0dp"
app:layout_constraintTop_toTopOf="@id/home_main_calendar" /> app:layout_constraintHeight_percent="0.5"
app:layout_constraintLeft_toLeftOf="@id/home_main_calendar"
app:layout_constraintTop_toBottomOf="@+id/home_main_calendar"
/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save