2015-10-05 52 views
0

我現在用這個的CoverFlow:https://github.com/davidschreiber/FancyCoverFlow習俗的CoverFlow圖像

我已經運行的代碼很好,但我需要我的項目看起來有點酷這樣的:

enter image description here

這條紅線是一樣的東西:

enter image description here

而且我想裏面添加圖像這個形狀。我怎樣才能做到這一點?

這裏是我的代碼:

MainActivity.java:

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.ImageView; 
import android.widget.RelativeLayout; 

import at.technikum.mti.fancycoverflow.FancyCoverFlow; 

public class MainActivity extends Activity { 
    FancyCoverFlow fancyCoverFlow; 
    ImageView imageView; 
    RelativeLayout backgroundLayout; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     fancyCoverFlow = (FancyCoverFlow) findViewById(R.id.fancyCoverFlow); 
     imageView = (ImageView) findViewById(R.id.imageView); 
     backgroundLayout = (RelativeLayout)findViewById(R.id.backgroundlayout); 

     final MyAdapter myAdapter = new MyAdapter(this); 
     fancyCoverFlow.setAdapter(myAdapter); 

     fancyCoverFlow.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 
      @Override 
      public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { 
       backgroundLayout.setBackgroundResource(myAdapter.getItem(position)); 
      } 

      @Override 
      public void onNothingSelected(AdapterView<?> parent) { 

      } 
     }); 
    } 
} 

MyAdapter.java:

import android.content.Context; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ImageView; 
import android.widget.RelativeLayout; 
import android.widget.TextView; 

import at.technikum.mti.fancycoverflow.FancyCoverFlow; 
import at.technikum.mti.fancycoverflow.FancyCoverFlowAdapter; 

public class MyAdapter extends FancyCoverFlowAdapter { 
    private int[] images = {R.drawable.rain,R.drawable.rain2,R.drawable.rain_forest, 
      R.drawable.rain,R.drawable.rain2,R.drawable.rain_forest}; 
    private String[] nameImage = {"Rain1", "Rain2", "Rain3", "Rain4", "Rain5", "Rain6"}; 
    private Context mContext; 


    public MyAdapter(Context mContext){ 
     this.mContext=mContext; 
    } 
    @Override 
    public int getCount() { 
     return images.length; 
    } 
    @Override 
    public Integer getItem(int i) { 
     return images[i]; 
    } 
    @Override 
    public long getItemId(int i) { 
     return i; 
    } 


    @Override 
    public View getCoverFlowItem(int i, View reuseableView, ViewGroup viewGroup) { 

     LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     reuseableView = inflater.inflate(R.layout.custom_layout, viewGroup, false); 
     RelativeLayout rlMain =(RelativeLayout) reuseableView.findViewById(R.id.rlMain); 
     rlMain.setLayoutParams(new FancyCoverFlow.LayoutParams(400,400)); 
     TextView txtName = (TextView) reuseableView.findViewById(R.id.txtNameimage); 
     ImageView ivImage = (ImageView) reuseableView.findViewById(R.id.imageView); 
     txtName.setText(nameImage[i]); 
     ivImage.setImageResource(images[i]); 
     return reuseableView; 
    } 
} 

activity_main.xml中:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:fcf="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" 
    android:background="@drawable/rain_forest" 
    android:id="@+id/backgroundlayout"> 

    <at.technikum.mti.fancycoverflow.FancyCoverFlow 
     android:id="@+id/fancyCoverFlow" 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:gravity="center" 
     fcf:maxRotation="80" 
     fcf:unselectedAlpha="0.3" 
     fcf:unselectedSaturation="0.0" 
     fcf:unselectedScale="0.4" 
     fcf:scaleDownGravity="0.5" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" /> 

</RelativeLayout> 

和custom_layout.xml :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/rlMain" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="350dp" 
     android:layout_height="350dp" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" /> 
    <TextView 
     android:id="@+id/txtNameimage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textStyle="bold" 
     android:textColor="#ffffff" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:text="Tên ảnh" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true"/> 
</RelativeLayout> 
+0

你想在你的coverflow後面添加水滴到你的所有圖片嗎? –

+0

您可以將它放在xml的coverflow後面,但它將是靜態的,不會與其他圖片一起移動。如果您想分別將其添加到每張照片中,最簡單的方法就是使用photoshop。將水滴作爲第一層,將雨水背景作爲第二層。 –

+0

當選擇fancycoverflow的項目時,背後的背景會改變,你的方式是否適用?你的意思是放水在ImageView的src在custom_layout.xml? – Khuong

回答

0

我已經通過使用Photoshop解決了這個問題。我認爲在這種情況下使用photoshop比其他方式更簡單。