Facebook
From domateo, 9 Years ago, written in XML.
This paste is a reply to trojkat from domateo - go back
Embed
Viewing differences between trojkat and Re: trojkat activity_main.xml
package com.     xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.
example.trojkat2d;


import android.support.v7.app.ActionBarActivity;
import android.graphics.Color;
import android.graphics.Path;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.PathShape;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;

public class MainActivity extends ActionBarActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                
                final Button pathButton = (Button) findViewById(R.id.button1);
                pathButton.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                                                
                                // Zdefiniowanie trojkata
                                Path p = new Path();
                                p.moveTo(50, 0);
                                p.lineTo(100,100);
                                p.lineTo(0,100);
                                p.lineTo(50,0);    
                                ShapeDrawable d = new ShapeDrawable(new PathShape(p, 100, 100));
                                d.setIntrinsicHeight(100);
                                d.setIntrinsicWidth(100);
                                d.getPaint().setColor(Color.BLUE);
                                final CheckBox checkBox = (CheckBox) findViewById(R.id.checkBox1);
                        if (checkBox.isChecked()) {
                                d.getPaint().setColor(Color.RED);
                                setShapeByDrawable(d);
                        }
                                setShapeByDrawable(d);
                        }
                        
                });
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
                // Inflate the menu; this adds items to the action bar if it is present.
                getMenuInflater().inflate(R.menu.main, menu);
                return true;
        }

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
                // Handle action bar item clicks here. The action bar will
                // automatically handle clicks on the Home/Up button, so long
                // as you specify a parent activity in AndroidManifest.xml.
                int id = item.getItemId();
                if (id == R.id.action_settings) {
                        return true;
                }
                return super.onOptionsItemSelected(item);
        }
        private void setShapeByDrawable(Drawable drawable) {
                ImageView reusableImageView = (ImageView) findViewById(R.id.imageView1);
                reusableImageView.setImageDrawable(drawable);
        }
}
trojkat2d.MainActivity" >

             android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

             android:id="@+id/imageView1"
                android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_margin="115px"
        android:layout_marginBottom="62dp"
        android:minHeight="120px"
        android:minWidth="120px" />

             android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="22dp"
        android:text="Trójkąt" />

             android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button1"
        android:layout_below="@+id/button1"
        android:layout_marginTop="22dp"
        android:text="Czerwony" />