Unknown On 2014년 7월 15일 화요일

xml부분 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dip" >

    <ImageView
        android:id="@+id/image"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter" />

    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignBottom="@id/image"
        android:layout_toRightOf="@id/image"
        android:layout_marginLeft="10dip"
        android:textColor="#000" />

</RelativeLayout>


main_Activity 부분

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Custom Dialog");
TextView tv = (TextView) dialog.findViewById(R.id.text);
tv.setText("Hello. This is a Custom Dialog !");
ImageView iv = (ImageView) dialog.findViewById(R.id.image);
iv.setImageResource(R.drawable.suji);
dialog.show();
}
}

setContentView() 메소드로 xml을 연결해주고 findViewById로 대화상자 내부의 TextView를 찾아서 내용을 입력하고, ImageView를 찾아서 사진을 넣어주면 됩니다. 이외에도 원하는 레이아웃대로 xml을 작성해서 넣으면 됩니다.
CusomDialog 띄우는 방법!





Leave a Reply

Subscribe to Posts | Subscribe to Comments

Powered by Blogger.