btn_red.xml


<?xml version="1.0" encoding="utf-8"?>
    <item android:state_pressed="true" >
        <shape>
            <solid
                android:color="#ef4444" />
            <stroke
                android:width="1dp"
                android:color="#992f2f" />
            <corners
                android:radius="3dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
    <item>
        <shape>
            <gradient
                android:startColor="#ef4444"
                android:endColor="#992f2f"
                android:angle="270" />
            <stroke
                android:width="1dp"
                android:color="#992f2f" />
            <corners
                android:radius="3dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
</selector>



layout.xml


<Button android:text="Button" android:id="@+id/button1" android:background="@drawable/btn_red"></Button>



참조 : http://www.dibbus.com/2011/02/gradient-buttons-for-android/







Posted by tenn
,

현재의 컨텐츠 레이아웃에서 콤포넌트 받아오기


Button btn = (Button)findViewById(R.id.button1);




다른 레이아웃에서 받아오기



        LayoutInflater factory = LayoutInflater.from(this);
        View main2 = factory.inflate(R.layout.main2, null);

        Button btn = (Button)main2.findViewById(R.id.btn);



Posted by tenn
,

[Android] ImageView

Android 2012. 7. 25. 14:07



ImageView iv = new ImageView(this);


LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);


lp.setMargins(20, 0, 20, 0); // 마진 설정은 LayoutParams에서


layout.addView(iv, lp);




imageview.setScaleType(ImageView.ScaleType.CENTER);

//이미지는 원래 크기. 중앙에 위치.


more


width, height 설정


iv.getLayoutParams().width = 100;

iv.getLayoutParams().height = 100;





Posted by tenn
,