2011-10-26 3 views
1

내 레이아웃에서 gif 이미지를 재생하는 방법이 혼란 스럽습니다. RelativeLayout을 사용하는 내 레이아웃과 이미지가 중심에 있습니다. GIF를 재생하는 방법을 찾고 있지만 예제에서는 gif 만 재생할 수있는 다른 위젯이 포함 된 레이아웃을 구현하는 방법을 알려주지 않습니다. 이 일을 도와주세요. 여기 gif 이미지를 상대적 레이아웃으로 재생

코드입니다 :

choosepet_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
android:background="@drawable/background" 
android:paddingTop="50px" 
android:paddingBottom="10px" 
> 

<TextView 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:background="@drawable/choose" 
android:layout_gravity="center" 
android:layout_marginBottom="10px" 
/> 

<Spinner 
android:id="@+id/pet" 
android:layout_gravity="center" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:prompt="@string/pettype" 
/> 
<ImageView 
android:id="@+id/petpic" 
android:layout_gravity="center" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:src="@drawable/cat" 
/> 

<RelativeLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:paddingRight="10px" 
android:paddingLeft="10px"> 

<RadioGroup 
android:orientation="horizontal" 
android:id="@+id/genderGroup" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignParentBottom="true" 
> 
<TextView 
android:text="Gender" 
android:id="@+id/textGender" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:textSize="20sp" 
android:layout_marginBottom="13px" 
android:textColor="#000000" 
/> 

<RadioButton 
android:id="@+id/maleRadio" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Male" 
android:layout_toRightOf="@+id/textGender" 
/> 

<RadioButton 
android:id="@+id/femaleRadio" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Female" 
android:layout_toRightOf="@+id/maleRadio" 
/> 
</RadioGroup>> 

<TextView 
android:text="Name" 
android:id="@+id/textName" 
android:layout_alignParentLeft="true" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:textSize="20sp" 
android:layout_marginBottom="11px" 
android:layout_above="@+id/genderGroup" 
android:textColor="#000000" 
android:layout_marginRight="12px" 
/> 

<EditText 
android:id="@+id/name" 
android:layout_width="150sp" 
android:layout_height="40sp" 
android:layout_toRightOf="@+id/textName" 
android:layout_above="@+id/genderGroup" 
/> 

<ImageButton 
android:id="@+id/process" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:src="@drawable/letsplay" 
android:background="@null" 
android:layout_toRightOf="@+id/genderGroup" 
android:layout_alignParentBottom="true" 
android:layout_marginBottom="38px" 
/> 

</RelativeLayout> 
</LinearLayout> 

이것은

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.choosepet_layout); 

    Spinner spinnerPet = (Spinner) findViewById(R.id.pet); 
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
      this, R.array.pet_array, android.R.layout.simple_spinner_item); 
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 

    spinnerPet.setAdapter(adapter); 
    EditText nameField = (EditText) findViewById(R.id.name); 
    nameField.requestFocus(); 
    ImageButton processButton = (ImageButton) findViewById(R.id.process); 
    processButton.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       Intent myIntent = new Intent(view.getContext(), petMain.class); 
       startActivityForResult(myIntent, 0); 
      } 
    }); 
    final ImageView imgPet = (ImageView) findViewById(R.id.petpic); 
    spinnerPet.setOnItemSelectedListener(new OnItemSelectedListener() { 
     public void onItemSelected(AdapterView<?>parent, 
       View view, int pos, long id){ 
      String petType = parent.getItemAtPosition(pos).toString(); 
      if(petType.equals("Anjing")){ 
       imgPet.setImageResource(R.drawable.dog); 
      }else{ 
       imgPet.setImageResource(R.drawable.cat); 
      } 
     } 
     @Override 
     public void onNothingSelected(AdapterView parent) { 
      // TODO Auto-generated method stub 
     } 
    }); 
} 

가 사전에 감사합니다 choosepet.java입니다!

답변

1

안드로이드 GIF를 디코딩 할 수 체재.

이 부분은 post입니다.

관련 문제