首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在android中制作CalendarView垂直卷轴

如何在android中制作CalendarView垂直卷轴
EN

Stack Overflow用户
提问于 2019-08-08 11:34:41
回答 1查看 2.3K关注 0票数 0

如何将日历布局更改为垂直模式?我在ScrollView中使用ScrollView。现在,我正在垂直滚动中实现向上和向下滚动视图,以获取上一个月或下一个月的日历。

我正试图像下面的CalendarView那样实现.

https://ibb.co/TLDFbrm "CalendarView就这样“请帮帮我,我有麻烦了。

代码语言:javascript
运行
复制
   <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <CalendarView
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                  android:layout_marginTop="5dp">
                </CalendarView>

        </LinearLayout>

    </ScrollView>

有什么想法吗?让我知道!谢谢..。

EN

回答 1

Stack Overflow用户

发布于 2019-08-08 12:09:50

按照下面的代码操作。

Activity_main.xml代码

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>  
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    xmlns:app="http://schemas.android.com/apk/res-auto"  
    xmlns:tools="http://schemas.android.com/tools"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    tools:context="ganeshannt.calendarview.MainActivity">  

    <TextView  
        android:id="@+id/date"  
        android:layout_width="0dp"  
        android:layout_height="51dp"  
        android:text="Date"  
        android:textAlignment="center"  
        android:textSize="45dp"  
        android:visibility="visible"  
        app:layout_constraintBottom_toBottomOf="parent"  
        app:layout_constraintHorizontal_bias="0.0"  
        app:layout_constraintLeft_toLeftOf="parent"  
        app:layout_constraintRight_toRightOf="parent"  
        app:layout_constraintTop_toTopOf="parent"  
        app:layout_constraintVertical_bias="0.219" />  

    <Button  
        android:id="@+id/btngocalendar"  
        android:layout_width="266dp"  
        android:layout_height="47dp"  
        android:text="Go to calendar"  
        tools:layout_editor_absoluteX="47dp"  
        tools:layout_editor_absoluteY="8dp" />  

</android.support.constraint.ConstraintLayout> 

创建新的calendar_layout.xml文件(File⇒new⇒Activity⇒Empty_activity)。

转到calendar_layout.xml,然后单击文本底部。此xml文件包含android应用程序的设计代码,并将其复制并粘贴到下面的代码中。

calendar_layout.xml代码

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
android:orientation="vertical" android:layout_width="match_parent"  
android:layout_height="match_parent">  

<CalendarView  
    android:id="@+id/calendarView"  
    android:layout_width="match_parent"  
    android:layout_height="wrap_content" />  
</LinearLayout>  

创建新的CalendarActivity.java文件(文件⇒新⇒Java类)。

在CalendarActivity.java中复制和粘贴下面的code.java编程是安卓的后端语言。不要替换您的包名,否则应用程序将无法运行。

CalendarActivity.java代码

代码语言:javascript
运行
复制
package ganeshannt.calendarview;  

import android.content.Intent;  
import android.os.Bundle;  
import android.support.annotation.Nullable;  
import android.support.v7.app.AppCompatActivity;  
import android.util.Log;  
import android.widget.CalendarView;  



public class CalendarActivity extends AppCompatActivity {  

    private  static final String TAG = "CalendarActivity";  
    private CalendarView mCalendarView;  
    @Override  
    protected void onCreate(@Nullable Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.calendar_layout);  
        mCalendarView = (CalendarView) findViewById(R.id.calendarView);  
        mCalendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {  
            @Override  
            public void onSelectedDayChange(CalendarView CalendarView, int year, int month, int dayOfMonth) {  
              String date = year + "/" + month + "/"+ dayOfMonth ;  
                Log.d(TAG, "onSelectedDayChange: yyyy/mm/dd:" + date);  
                Intent intent = new Intent(CalendarActivity.this,MainActivity.class);  
                intent.putExtra("date",date);  
                startActivity(intent);  

            }  
        });  
    }  
}  
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57411626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档