Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Android

एंड्रॉइड में कोटलिन का उपयोग करके इमेजव्यू में इमेज को एंगल से कैसे घुमाएं

एंड्रॉइड में कोटलिन का उपयोग करके इमेजव्यू में इमेज घुमाना

यह उदाहरण दर्शाता है कि एंड्रॉइड में कोटलिन का उपयोग करके इमेजव्यू में इमेज को एंगल से कैसे घुमाया जाए।

चरण 1 - नया प्रोजेक्ट बनाएं

एंड्रॉइड स्टूडियो में एक नया प्रोजेक्ट बनाएं: File → New Project पर जाएं और सभी आवश्यक विवरण भरकर नया प्रोजेक्ट बनाएं।

चरण 2 - लेआउट फ़ाइल में कोड जोड़ें

res/layout/activity_main.xml में निम्नलिखित कोड जोड़ें:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="https://schemas.android.com/apk/res/android"
    xmlns:tools="https://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="2dp"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="600dp"
        android:src="@drawable/image" />

    <Button
        android:layout_above="@+id/imageView"
        android:id="@+id/btnRotate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerInParent="true"
        android:text="व्यू घुमाएं"
        android:textStyle="bold" />

</RelativeLayout>

चरण 3 - MainActivity.kt में कोड जोड़ें

import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {
    lateinit var imageView: ImageView
    lateinit var btnRotate: Button

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        title = "KotlinApp"
        imageView = findViewById(R.id.imageView)
        btnRotate = findViewById(R.id.btnRotate)
        btnRotate.setOnClickListener { imageView.rotation = 90f }
    }
}

चरण 4 - AndroidManifest.xml में कोड जोड़ें

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android" package="com.example.q11">
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

ऐप चलाएं

अपने एंड्रॉइड डिवाइस को कंप्यूटर से कनेक्ट करें। एंड्रॉइड स्टूडियो में प्रोजेक्ट की एक्टिविटी फ़ाइल खोलें और टूलबार से Run आइकन पर क्लिक करें। अपना मोबाइल डिवाइस चुनें और डिवाइस पर डिफ़ॉल्ट स्क्रीन देखें।

  1. Android में कोड का उपयोग करके ImageView का मार्जिन कैसे सेट करें Android में कोड का उपयोग करके ImageView का मार्जिन कैसे सेट करें

    परिचयरनटाइम पर व्यू के मार्जिन को बदलने के लिए, उसके `LayoutParams` को प्राप्त करें, मार्जिन सेट करें, और फिर `setLayoutParams()` कॉल करें।कार्यान्वयनचरण 1: लेआउट (activity_main.xml)<ImageView android:id=@+id/imageView android:layout_width=wrap_content android:layout_height=wrap_content android:b

  1. Android में ImageView की इमेज को कोण से कैसे घुमाएं? Android में ImageView की इमेज को कोण से कैसे घुमाएं?

    Android में ImageView रोटेशन यह उदाहरण दर्शाता है कि setRotation() विधि का उपयोग करके ImageView में प्रदर्शित इमेज को किसी भी कोण पर कैसे घुमाया जाए। चरण 1: नया प्रोजेक्ट बनाएं Android Studio में File → New Project चुनें। चरण 2: लेआउट में ImageView और Button जोड़ें (activity_main.xml) <?xml ver

  1. एंड्रॉइड में स्मूथ इमेज रोटेशन कैसे बनाएं? एंड्रॉइड में स्मूथ इमेज रोटेशन कैसे बनाएं?

    एंड्रॉइड में XML एनिमेशन से स्मूथ इमेज रोटेशन यह उदाहरण दिखाता है कि res/anim/ फोल्डर में XML एनिमेशन परिभाषित करके इमेज को स्मूथली कैसे घुमाया जाता है। चरण 1: नया प्रोजेक्ट बनाएं Android Studio में File → New Project चुनकर नया प्रोजेक्ट बनाएं। चरण 2: लेआउट XML res/layout/activity_main.xml: <?x