Button drawableLeft 자바에서 설정하기

안드로이드/android 2013. 3. 27. 16:11

Drawable img = getContext().getResources().getDrawable( R.drawable.smiley );
img.setBounds( 0, 0, 60, 60 );
txtVw.setCompoundDrawables( img, null, null, null );

or

Drawable img = getContext().getResources().getDrawable( R.drawable.smiley );
txtVw.setCompoundDrawablesWithIntrinsicBounds( img, null, null, null );
// 아이콘 정렬

setCompoundDrawablesWithIntrinsicBounds( 왼쪽, , 오른쪽, 아래 );

view getId() string 문자 알아보기(EntryName)

안드로이드/android 2013. 3. 26. 11:04

View.OnClickListener clickListener = new View.OnClickListener() {

// TODO clickListener

   public void onClick(final View v) {

       switch (v.getId()) {

           case R.id.photo1:

           case R.id.photo2:

           case R.id.photo3:

            Log.i("ID값",v.getResources().getResourceEntryName(v.getId()));


// 결과 photo1, photo2, photo3

            break;

       }

   }

};

GridView stretchMode

안드로이드/android 2013. 2. 22. 17:39

android:stretchMode android:numColumns="auto_fit" 으로 지정한 경우 열의 나머지 공간 처리 지정


android:stretchMode="columnWidth" : 위젯이 격자 내부를 가득채우게 함

android:stretchMode="spacingWidth" :  남는공간을 여백으로 채움

shape 레이아웃 모서리 둥글게 하기

안드로이드/android 2013. 1. 25. 10:46


// res/drawable/shape.xml

============================================================================

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">

  <solid android:color="#90000000"/>

  <stroke android:width="4dp" android:color="#50000000"

            android:dashWidth="1dp" android:dashGap="0dp" />

  <padding android:left="7dp" android:top="7dp"

            android:right="7dp" android:bottom="7dp" />

  <corners android:radius="10dp" />  

</shape>



<TextView 

            android:layout_width="wrap_content" android:layout_height="wrap_content"

            android:textSize="16sp" android:textStyle="bold" android:text="모서리 둥글게 하자" android:textColor="#ffffff"

            android:gravity="center" android:background="@drawable/shape"

             android:padding="16px"

        />


배경 이미지 repeat 시키기

안드로이드/android 2013. 1. 25. 10:41

1x1 이미지를 배경으로 반복해서 보이게 하기


====================================================================

// res/drawble/background_image.xml

==================================================================

<?xml version="1.0" encoding="utf-8"?>

<bitmap

  xmlns:android="http://schemas.android.com/apk/res/android"

  android:src="@drawable/background" android:tileMode="repeat"

/>


// res/layout/background.xml

<LinearLayout android:background="@drawable/background_image.xml" />



=======================================================================

// theme manifest

========================================================================

/res/values/theme.xml


<style name="Theme.BackGround" parent="android:Theme">

        <item name="android:windowBackground">@drawable/background</item>

        <item name="android:windowNoTitle">true</item>

    </style>


/manifest.xml

<activity android:name=".Test" android:label="@string/app_name" android:screenOrientation="landscape" 

        android:theme="@style/Theme.BackGround" />