我正在实现水平滚动文本视图列表,类似于带有翻页的电子书。我使用显示 TextViews 的 Gallery 小部件。我面临的第一个问题是每页的左右边缘看起来都是圆形的。
这是示例代码:
主要的.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>
页面.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;
}
}
}
任何想法如何获得例如标题栏上的页面边缘?也许另一种实现目标的方法?