Skip to content

Commit

Permalink
修改item背景、内容
Browse files Browse the repository at this point in the history
  • Loading branch information
chiemy committed Aug 30, 2014
1 parent 7c91d3d commit f971248
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
Binary file added res/drawable-mdpi/card_bg.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 9 additions & 8 deletions res/layout/frag_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/card_bg"
>

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceLarge"
/>

<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />

</RelativeLayout>
13 changes: 13 additions & 0 deletions src/com/example/cviewpager/JellyPagerAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.cviewpager;

import android.view.View;

public interface JellyPagerAdapter{

public int getCount();

public Object getItem(int position);

public View getView(int position,View convertView);

}
46 changes: 29 additions & 17 deletions src/com/example/cviewpager/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,57 @@
package com.example.cviewpager;


import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends FragmentActivity {
private LayoutInflater inflater;
MyViewPager pager;
JellyViewPager pager;
int currentItem;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
inflater = LayoutInflater.from(this);
pager = (MyViewPager) findViewById(R.id.myViewPager1);
pager = (JellyViewPager) findViewById(R.id.myViewPager1);
pager.setAdapter(new MyAdapter());
pager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
Toast.makeText(MainActivity.this, "" + arg0, Toast.LENGTH_SHORT).show();
}

@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}

@Override
public void onPageScrollStateChanged(int arg0) {
}
});
}

public void onClick(View view) {
pager.setCurrentItem(pager.getCurrentItem() + 1);
switch(view.getId()){
case R.id.preBtn:
pager.showPre();
break;
case R.id.nextBtn:
pager.showNext();
break;
}
}

public class MyAdapter implements SampleAdapter{
public class MyAdapter implements JellyPagerAdapter{

@Override
public int getCount() {
return 5;
return 10;
}

@Override
Expand All @@ -40,20 +60,12 @@ public Integer getItem(int position) {
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position,View convertView,ViewGroup container) {
public View getView(int position,View convertView) {
if(convertView == null){
convertView = inflater.inflate(R.layout.frag_layout, null);
convertView.setBackgroundColor(Color.BLUE);
}
ImageView iv = ViewHolder.get(convertView, R.id.imageView1);
TextView tv = ViewHolder.get(convertView,R.id.tv);
tv.setText(position + "");
iv.setImageResource(getItem(position));
return convertView;
}

Expand Down

0 comments on commit f971248

Please sign in to comment.