2012-07-20 49 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