Assets papkasinan su’wretler
Joqaridag’ilarda joybardag’i ko’rinisler derek sipatinda res/drawables papkasina jaylastirilg’an ha’m ImageView elementinde ko'rsetilgen. Biraq, su’wretlerdi printsipial tu’rde usi papkag’a jaylastiriw sha’rt emes. Fayllar, sonday-aq, assets papkasinda jaylasqan boliwi mu’mkin . Kelin’, bunday grafikaliq fayllar menen qanday islewdi ko'rip shig’ayiq.
Da’slep joybarg’a assets papkasin qosamiz. Bunin’ ushin Android Studio-da app katalogin basamiz ha’m payda bolg’an kontekst menyusinan New - > Directory - di tan’laymiz:
Son’ payda bolg’an aynada src\main\assets elementin tan’laymiz ha’m oni joybarg’a qosiw ushin Enter tu’ymesin basamiz:
Usi papkag’a bir neshe su’wret qosamiz:
Son’ payda bolg’an aynada src\main\assets elementin tan’laymiz ha’m oni joybarg’a qosiw ushin Enter tu’ymesin basamiz:
Usi papkag’a bir neshe su’wret qosamiz:
Son’ payda bolg’an aynada src\main\assets elementin tan’laymiz ha’m oni joybarg’a qosiw ushin Enter tu’ymesin basamiz:
Usi papkag’a bir neshe su’wret qosamiz:
Son’ payda bolg’an aynada src\main\assets elementin tan’laymiz ha’m oni joybarg’a qosiw ushin Enter tu’ymesin basamiz:
Usi papkag’a bir neshe su’wret qosamiz:
Son’ activity_main.xml faylida ImageView elementin aniqlaymiz:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/image"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
|
Assets papkasinan MainActivity – dag’i ImageView elementine su’wret ju’kleymiz:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package com.example.viewapp;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;
import java.io.IOException;
import java.io.InputStream;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imageView = findViewById(R.id.image) ;
String filename = "dubi2.png";
try(InputStream inputStream = getApplicationContext().getAssets().open(filename)){
Drawable drawable = Drawable.createFromStream(inputStream, null);
imageView.setImageDrawable(drawable);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
}
catch (IOException e){
e.printStackTrace();
}
}
}
|
Fayldi ju’klep aliw ushin getApplicationContext()getAssets(). open(filename) ma’nisi ja’rdeminde InputStream ag’imin aliwimiz kerek .
Drawable.createFromStream(inputStream, null) ni shaqiriw kiriw ag’iminan Drawable obiektini jaratadi.
imageView.setImageDrawable(d) usuli Drawable -di ImageView -g’a ju’kleydi .
Do'stlaringiz bilan baham: |