Soru & Cevap

AndroidStudio nesnenin boyutunu kod ile nasıl değiştirilir ...

25.10.2019 - 06:54

Takvim ile ilgili basit bir uygulama yazıyorum. Takvim nesnesi ilk açıldığında ekranı kaplıyacak şekilde geliyor. ben herhangi bir güne tıkladığımda bu nesnenin animasyonlu bir şekilde yüksekliğinin küçülmesini istiyorum ama bir türlü takvim nesnesinin boyutunu nasıl değiştireceğimi veya yüksekliği nasıl animasyonlu  küçüleceğini bulamadım. Bu konuyla ilgili yardımcı olursanız çok sevinirim.

activity_main

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <LinearLayout
        android:id="@+id/calendar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <com.github.sundeepk.compactcalendarview.CompactCalendarView
            android:id="@+id/compactcalendar_view"
            android:layout_gravity="center"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            app:compactCalendarCurrentDayBackgroundColor="#fff"
            app:compactCalendarCurrentDayTextColor="#B71C1C"
            app:compactCalendarCurrentSelectedDayBackgroundColor="#E57373"
            app:compactCalendarCurrentSelectedDayTextColor="#fff"
            app:compactCalendarMultiEventIndicatorColor="#fff"
            app:compactCalendarTextColor="#000"
            app:compactCalendarTextSize="12sp" />
    </LinearLayout>

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

        <TextView
            android:id="@+id/textView3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView" />

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button" />
    </LinearLayout>

</LinearLayout>

MainActivity:

package com.example.hesaptut;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.github.sundeepk.compactcalendarview.CompactCalendarView;
import com.github.sundeepk.compactcalendarview.domain.Event;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class MainActivity extends AppCompatActivity {

    CompactCalendarView compactCalendarView;
    Animation Animasyonumuz;
    private SimpleDateFormat dateFormatMounth = new SimpleDateFormat("MMMM - yyyy", Locale.getDefault());

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(false);
        actionBar.setTitle(null);

        compactCalendarView = findViewById(R.id.compactcalendar_view);
        compactCalendarView.setUseThreeLetterAbbreviation(true);

        Event evl = new Event(Color.WHITE, 1571875200000L, "Hastane randevusu");
        compactCalendarView.addEvent(evl);

        compactCalendarView.setListener(new CompactCalendarView.CompactCalendarViewListener() {
            @Override
            public void onDayClick(Date dateClicked) {
                Context context = getApplicationContext();
                if (dateClicked.toString().compareTo("Thu Oct 24 00:00:00 GMT+03:00 2019") == 0) {
                    Toast.makeText(context, "Hastane randevusu", Toast.LENGTH_SHORT).show();
                    animasyonbasla();

                } else {
                    Toast.makeText(context, "Hatalı Deneme yanılma\n" + dateClicked.toString(), Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onMonthScroll(Date firstDayOfNewMonth) {
                actionBar.setTitle(dateFormatMounth.format(firstDayOfNewMonth));
            }
        });
    }

    private void animasyonbasla() {
        Animation anim = AnimationUtils.loadAnimation(this, R.anim.anim);
        anim.reset();
        LinearLayout calendar = findViewById(R.id.calendar);
        LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,450);

        calendar.clearAnimation();
        calendar.startAnimation(anim);
        calendar.setLayoutParams(lp);
    }

}

animasyon sayfası:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:duration="3000"
        android:fromXScale="1.0"
        android:fromYScale="1.0"

        android:toXScale="1.0"
        android:toYScale="0.5"></scale>
</set>

 

286 Görüntülenme

1 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.