Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java RecyclerView-动态高度,无需移动元件_Java_Android_Android Layout_Android Recyclerview_Kotlin - Fatal编程技术网

Java RecyclerView-动态高度,无需移动元件

Java RecyclerView-动态高度,无需移动元件,java,android,android-layout,android-recyclerview,kotlin,Java,Android,Android Layout,Android Recyclerview,Kotlin,我需要的是: 我尝试使用RecyclerView来实现这一点,该视图根据模型动态设置项目的高度。我正在使用 布局: <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/

我需要的是:

我尝试使用
RecyclerView
来实现这一点,该视图根据模型动态设置项目的高度。我正在使用

布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    card_view:cardUseCompatPadding="true">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:orientation="vertical"
    android:gravity="center|bottom"
    android:layout_weight="0">

    <TextView
        android:id="@+id/teacher"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:padding="5dp"
        android:textColor="@android:color/black"
        android:textSize="16sp" />
    <TextView
        android:id="@+id/room"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/teacher"
        android:padding="5dp"
        android:textColor="@android:color/black"
        android:textSize="16sp" />

    <TextView
        android:id="@+id/subject"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#1976D2"
        android:gravity="center_horizontal"
        android:layout_alignParentBottom="true"
        android:paddingBottom="8dp"
        android:paddingTop="8dp"
        android:textColor="#ffffff"
        android:textSize="13sp"
        android:maxLines="3"
        android:lines="1" />
</RelativeLayout>

</android.support.v7.widget.CardView>
它与会议所需的小时数相乘

问题是,如果在两个小时的会议之后还有一个小时的会议,那么它就会被转移到第二天

见:

两小时会议:

一小时会议:


如何在适配器中修复此问题/如何在不移动图元的情况下调整高度?

将库导入到项目中。 通过maven抓取

<dependency>
  <groupId>com.github.alamkanak</groupId>
  <artifactId>android-week-view</artifactId>
  <version>1.2.6</version>
  <type>aar</type>
</dependency>
在xml布局中添加WeekView

<com.alamkanak.weekview.WeekView
        android:id="@+id/weekView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:eventTextColor="@android:color/white"
        app:textSize="12sp"
        app:hourHeight="60dp"
        app:headerColumnPadding="8dp"
        app:headerColumnTextColor="#8f000000"
        app:headerRowPadding="12dp"
        app:columnGap="8dp"
        app:noOfVisibleDays="3"
        app:headerRowBackgroundColor="#ffefefef"
        app:dayBackgroundColor="#05000000"
        app:todayBackgroundColor="#1848adff"
        app:headerColumnBackground="#ffffffff"/>
根据需要实施WeekView.MonthChangeListener、WeekView.EventClickListener、WeekView.EventLongPressListener

在WeekView.MonthChangeListener.onMonthChange()回调中为WeekView提供事件。请记住,日历预先加载连续三个月的事件以启用无延迟滚动

MonthLoader.MonthChangeListener mMonthChangeListener = new MonthLoader.MonthChangeListener() {
    @Override
    public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
        // Populate the week view with some events.
        List<WeekViewEvent> events = getEvents(newYear, newMonth);
        return events;
    }
};
MonthLoader.MonthChangeListener=new MonthLoader.MonthChangeListener(){
@凌驾
每月更改的公共列表(整年、整月){
//用一些事件填充周视图。
List events=getEvents(newYear,newMonth);
返回事件;
}
};

谢谢,我不知道我怎么在研究中没有发现这一点。我想指出的是,week view github链接是使用自定义视图而不是recycler视图完成的。这不是一个答案。该问题询问了recyclerview,而您将他指向自定义视图
<com.alamkanak.weekview.WeekView
        android:id="@+id/weekView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:eventTextColor="@android:color/white"
        app:textSize="12sp"
        app:hourHeight="60dp"
        app:headerColumnPadding="8dp"
        app:headerColumnTextColor="#8f000000"
        app:headerRowPadding="12dp"
        app:columnGap="8dp"
        app:noOfVisibleDays="3"
        app:headerRowBackgroundColor="#ffefefef"
        app:dayBackgroundColor="#05000000"
        app:todayBackgroundColor="#1848adff"
        app:headerColumnBackground="#ffffffff"/>
/ Get a reference for the week view in the layout.
mWeekView = (WeekView) findViewById(R.id.weekView);

// Set an action when any event is clicked.
mWeekView.setOnEventClickListener(mEventClickListener);

// The week view has infinite scrolling horizontally. We have to provide the events of a
// month every time the month changes on the week view.
mWeekView.setMonthChangeListener(mMonthChangeListener);

// Set long press listener for events.
mWeekView.setEventLongPressListener(mEventLongPressListener);
MonthLoader.MonthChangeListener mMonthChangeListener = new MonthLoader.MonthChangeListener() {
    @Override
    public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
        // Populate the week view with some events.
        List<WeekViewEvent> events = getEvents(newYear, newMonth);
        return events;
    }
};