abuybuy
abuybuy

Reputation: 819

play gif image in relative layout

i am confusing how to play gif image in my layout. my layout using RelativeLayout and the image is at center. i've looking the way to play the gif but the example is not tell me how to implement it to my layout that contains another widget there not only to play the gif alone. please help me to do this.

here is the code:

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>

and this is the choosepet.java

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  
        }
     });
}

thank you in advance!

Upvotes: 1

Views: 3469

Answers (2)

DouO
DouO

Reputation: 4914

Android can decode gif format.

take a look at this post.

Upvotes: 1

Umar Qureshi
Umar Qureshi

Reputation: 6115

as far as i know android does not support gif animation you have to create the animation by other ways like series of images

like in example linked below

http://yekmer.posterous.com/how-to-make-a-loading-animator-in-android

Upvotes: 3

Related Questions