Mobile Computing Systems


Download 10.9 Kb.
bet3/4
Sana18.06.2023
Hajmi10.9 Kb.
#1563379
1   2   3   4

1. Using Drawables

1(a) Image from Project Resource


<ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/img1" android:src="@drawable/my_image"/>
ImageView i = new ImageView(this);
i.setImageResource(R.drawable.my_image);
LinearLayout ll = new LinearLayout(this);
ll.addView(i);
setContentView(ll); //instead of setContentView(R.layout.somexmllayoutfile)

1(b) XML with drawable properties

  • e.g. Transition Drawable: res/drawable/something.xml
  • Now, take an ImageView to show it (them):

<transition xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/image1"> <item android:drawable="@drawable/image2"> transition>
TransitionDrawable td;
td = (TransitionDrawable)
getResources().getDrawable(R.drawable.something);
td.setCrossFadeEnabled(true);
ImageView img; img = (ImageView) findViewById(R.id.img1); img.setImageDrawable(td);
td.startTransition(5000);

Nine Patch Image

  • Regular .png images + defining stretchable regions

From a terminal:
Run the draw9patch command from your SDK sdk/tools directory to launch the tool.

2. Using Canvas

  • Canvas holds all of your draw*() calls.
  • Drawing is performed upon an underlying Bitmap.
  • Two ways to use the Canvas of a View:
    • Custom View
    • Surface View

Bitmap b = Bitmap.createBitmap(100, 100,
Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); Paint p = new Paint(); p.setColor(Color.GREEN); c.drawRect(10, 10, 90, 90, p);

Download 10.9 Kb.

Do'stlaringiz bilan baham:
1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling