세 가지 다른 xml 레이아웃 사이에서 슬라이드하는 갤러리 응용 프로그램을 만들려고합니다. 응용 프로그램은 매우 잘못된 같습니다 BaseAdapter의사용자 지정 어댑터를 사용하여 여러보기 간 이동
linear.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="one"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="two"
android:gravity="center"
android:layout_weight="1"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three"
android:layout_gravity="right"/>
</LinearLayout>
table.xml:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="What is your name?"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"/>
<TableRow>
<TextView android:text="@string/firstname"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<EditText android:text="John"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</TableRow>
<TableRow>
<TextView android:text="@string/lastname"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<EditText android:text="Poe"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</TableRow>
</TableLayout>
and the gallery.xml:
<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
내 구현 :
내 XML 파일
은public class LayoutsAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public LayoutsAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return 3;
}
@Override
public Object getItem(int i) {
switch (i) {
case 0:
return R.layout.linear;
case 1:
return R.layout.table;
case 2:
return R.layout.relative;
default:
return -1;
}
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View convertView, ViewGroup viewGroup) {
convertView = mInflater.inflate((Integer)getItem(i), null);
return convertView;
}
}
나는 안드로이드 매우 새로운 오전, 그래서 기대 너의 도움으로.
ViewPageIndicator는 ViewPager와 함께 작동하지만 표준 SDK 또는 호환성 패키지에 포함되어 있지 않습니다. 먼저 fragment가있는 ViewPager로 구현하고 필요할 경우 ViewPageIndicator를 사용합니다. –
감사합니다. 내 코드로는 아무 것도 할 수 없다는 뜻입니까? – user1256821
필자는 ViewPager/ViewPageIndicator가 최소한 호환성 라이브러리에 의해 지원된다는 이점이 있다고 생각합니다. 그리고 3.0+가 포함 된 SDK의 일부이므로이를 달성하기 위해 수행중인 작업을 광범위하게 테스트해야합니다. ViewPager는 전환을 처리하기 때문에 레이아웃 등을 재사용 할 수 있습니다. 그래도 개별 페이지를 만들어야합니다. –