2012-07-20 68 views
0

我正在實施水平滾動textview列表,就像電子書的翻頁頁面。我使用圖庫小部件來顯示TextViews。我面臨的第一個問題是每個頁面的左右邊緣看起來圓潤。android畫廊textview水平列表圓角邊緣

下面是示例代碼:

main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <Gallery android:id="@+id/gallery" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:spacing="0px"/>   

</LinearLayout> 

page.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gallery_item" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView android:id="@+id/textView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#000"/> 

</LinearLayout> 

GalleryActivity.java

import android.app.Activity; 
import android.content.Context; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.BaseAdapter; 
import android.widget.Gallery; 
import android.widget.TextView; 

public class GalleryActivity extends Activity { 

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

     Gallery gallery = (Gallery) findViewById(R.id.gallery); 
     gallery.setAdapter(new GalleryAdapter(this)); 
    } 

    private class GalleryAdapter extends BaseAdapter { 

     private Context context; // needed to create the view 

     public GalleryAdapter(Context c) { 
      context = c; 
     } 

     public int getCount() { 
      return 5; 
     } 

     public Object getItem(int position) { 
      return position; //TODO: get the object on the position 
     } 

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

     public View getView(int position, View convertView, ViewGroup parent) { 
      View v; 

      if(convertView == null) 
       v = LayoutInflater.from(context).inflate(R.layout.page, parent, false); 
      else 
       v = convertView; 


      TextView tv = (TextView) v.findViewById(R.id.textView); 
      tv.setText("Page" + position); 

      return v; 
     } 
    } 
} 

任何想法如何讓頁面邊緣喜歡在例如標題欄?也許另一種實現目標的方式?

回答

0

在page.xml中,而不是givin match_parent爲佈局提供fxd寬度併爲txtview提供sm填充。 並且FYI Gallery已被棄用,請改用視圖分頁器。 查看傳呼機也帶有兼容性包:http://developer.android.com/tools/extras/support-library.html

如果你不能給一個FX寬度,那麼你只能嘗試與填充,這可能會發現我的朋友

+0

因爲我知道ViewPager來自V3.0,但我想這個功能也適用於以前的版本。給定寬度會使視圖不靈活。是不是可以更改圖庫的佈局,以便它不顯示四捨五入的邊緣飛機? – 2012-07-21 11:53:09

+0

我是Android應用程序開發新手,它並不瞭解兼容性套件。謝謝你的信息,我會看看它。 – 2012-07-23 10:31:04

+0

不要讓4get接受它作爲你的答案,如果你發現它有用 – user987171 2012-07-23 11:57:28