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 { @@ -32,8 +32,8 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
buildFeatures {
viewBinding true
@ -47,7 +47,7 @@ dependencies { @@ -47,7 +47,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-livedata-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'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
@ -58,7 +58,7 @@ dependencies { @@ -58,7 +58,7 @@ dependencies {
// room持久化库
def room_version = "2.5.0"
def room_version = '2.6.1'
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
// 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; @@ -2,6 +2,7 @@ package cc.niushuai.didicheck.ui.main.home;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -50,16 +51,15 @@ public class HomeFragment extends Fragment { @@ -50,16 +51,15 @@ public class HomeFragment extends Fragment {
ConstraintLayout rootLayout = fragmentHomeBinding.getRoot();
TextView homeTitleTextView = fragmentHomeBinding.homeTitleTextView;
homeTitleTextView.setGravity(Gravity.CENTER);
homeViewModel.getTitle().observe(getViewLifecycleOwner(), value -> homeTitleTextView.setText(value));
homeTitleTextView.setText("未完待续...");
CalendarView homeMainCalendar = fragmentHomeBinding.homeMainCalendar;
homeMainCalendar.setDate(DateUtil.offsetDay(new Date(), -10).getTime());
homeViewModel.getSelectDate().observe(getViewLifecycleOwner(), new Observer<Date>() {
@Override
public void onChanged(Date value) {
homeMainCalendar.setDate(DateUtil.millisecond(value));
Log.d(this.getClass().getSimpleName(), "set date to " + value);
}
homeMainCalendar.setDate(DateUtil.date().getTime());
homeMainCalendar.setOnDateChangeListener((calendarView, year, month, day) -> {
long date = calendarView.getDate();
Log.d("tagxx", "tag = " + DateUtil.date(date).toDateStr());
});
RecyclerView homeDataZoneRecyclerView = fragmentHomeBinding.homeDataZoneRecyclerView;

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

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