banner



How To Draw A Rectangle With App Inventor 2

Android Shape Drawables Tutorial

Why should you use ShapeDrawables?

Are at that place any disadvantages?

Allow'south start coding

Create a simple gradient ShapeDrawable in XML

shape_drawable_example_1.xml

Some useful attributes that you lot tin use when defining a shape:

          android:shape= "oval"        
          android:radius="21dp"                  
          android:bottomLeftRadius="10dp"        
          android:color=@colour/your_color_name        
          android:startColor=@color/your_color_name
android:centerColor=@colour/your_color_name
android:endColor=@color/your_color_name
          android:blazon="radial"        
          android:layout_height="40dp"
android:layout_width="10dp"
          android:width="2dp"
android:colour=@color/your_beautiful_color
          android:dashGap="1dp"
android:dashWidth="4dp"

Permit's use our shape in a View

          <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:groundwork="@drawable/my_custom_circle"
android:text="@string/hello_world" />
          android:src="@drawable/my_custom_circle"        
          ImageView myImageView = (ImageView) findViewById(R.id.my_image_view);          imageView.setImageResource(R.drawable.my_custom_circle);        

Modify shapes using Coffee

          Drawable drawable = getDrawable(R.drawable.button_shape);        
          GradientDrawable gradientDrawable = (GradientDrawable) drawable;        
          gradientDrawable.setColor(ContextCompat.getColor(this, R.color.colorPrimary));
gradientDrawable.setShape(GradientDrawable.OVAL);
gradientDrawable.setStroke(12, Color.CYAN);

Define shapes using Coffee

          RoundRectShape roundRectShape = new RoundRectShape(new bladder[]{
10, x, ten, 10,
10, 10, 10, x}, null, null);
ShapeDrawable shapeDrawable = new ShapeDrawable(roundRectShape);
shapeDrawable.getPaint().setColor(Colour.parseColor("#FFFFFF"));
ImageView myImageView = findViewById(R.id.my_image_view);
myImageView.setBackground(shapeDrawable);
// or you can use myImageView.setImageDrawable(shapeDrawable);

Now it is time for the concluding step. Allow's recreate this Spotify's gradient using our new skills.

Original image

Our recreation

Source: https://medium.com/android-news/android-shape-drawables-tutorial-17fbece6fef5

Posted by: browncorgentor.blogspot.com

0 Response to "How To Draw A Rectangle With App Inventor 2"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel