0

我實現水平滾動視圖,該物品,其中含有的ImageView和一個TextView的Android水平類別與圖像查看

這是我的主要活動:

public class MainActivity extends Activity implements OnClickListener{ 
    List elementlist; 
    LinearLayout layout; 

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

     elementlist=new ArrayList<Element>(); 

     elementlist.add(new Element("Item 1", "p1")); 
     elementlist.add(new Element("Item 2", "p2")); 
     elementlist.add(new Element("Item 3", "p3")); 
     elementlist.add(new Element("Item 4", "p4")); 
     elementlist.add(new Element("Item 5", "p5")); 

     layout=(LinearLayout)findViewById(R.id.lay); 


     populate_list(); 

    } 

    private void populate_list() 
    { 

     Iterator<Element> i=elementlist.iterator(); 
     while(i.hasNext()) 
     { 
      Element e= (Element)i.next(); 

      LayoutInflater inflater=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); 
      View v=inflater.inflate(R.layout.list_element, null); 

      ImageView iw=(ImageView)v.findViewById(R.id.imageView1); 
      TextView tw=(TextView)v.findViewById(R.id.textView1); 
      iw.setImageDrawable(getResources().getDrawable(getResources().getIdentifier(e.getImagename(), "drawable", this.getPackageName()))); 
      tw.setText(e.getDisplayname()); 

      layout.addView(v); 
     } 



    } 
} 

元素類:

public class Element { 
private String displayname; 
private String imagename; 
public Element(String displayname, String imagename) { 
    this.displayname = displayname; 
    this.imagename = imagename; 
} 

public String getDisplayname() { 
    return displayname; 
} 

public String getImagename() { 
    return imagename; 
}} 

activity_main.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" > 

    <HorizontalScrollView 
     android:id="@+id/horizontalScrollView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" > 

     <LinearLayout 
      android:id="@+id/lay" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" > 
     </LinearLayout> 
    </HorizontalScrollView> 

</RelativeLayout> 

而且listelement.xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 


    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" /> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/imageView1" 
     android:layout_centerHorizontal="true" 
     android:background="#000000" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentLeft="true" 
     android:orientation="vertical" > 


     <TextView 
     android:id="@+id/textView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#ffffff" /> 


    </LinearLayout> 

</RelativeLayout> 

現在,我的情況是,我有兩個要求:

  1. 雖然滾動列表的大小應減少(如在畫廊的情況下,諾基亞N72,N95等)

  2. 滾動結束後,列表會自動跳到最近的項目,尺寸再次增加,即該項目的寬度適合屏幕寬度或至少出現在中心。

我該如何滿足我的要求?

我想正是做這樣

While the layout is static

當用戶滾動,它應該是這樣的: While the user is scrolling

回答

1

從你的問題,我認爲在大小需減量不與位移成正比,即你有1個更大的尺寸和1個更小的尺寸

繼續我的假設,我建議你通過問題 - Complete Working Sample of the Gmail Three-Fragment Animation Scenario?,它會告訴你四個處理你需要調整大小動畫的實現

+0

其實是的,它不需要完全成比例,但我需要一個漸變縮放。 – gaurav414u 2013-12-22 07:59:49

+0

我已經通過使用一些矩陣變換和數學在垂直自定義ListView中實現了這一點。在這種情況下,縮放和旋轉與兒童與列表中心的距離成正比,而且看起來很酷。 – gaurav414u 2013-12-22 08:01:29