sách gpt4 ai đã đi

Android - 滑动 fragment

In lại 作者:太空宇宙 更新时间:2023-11-03 12:58:05 26 4
mua khóa gpt4 Nike

我正在尝试实现从 fragment1 过渡到 fragment2 的滑动动画。我正在使用 setCustomAnimations 方法。而且我知道我需要使用框架方法来替换 fragment 。

我的代码:

package com.example.fragmentss;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity implements MyListFragment.OnItemSelectedListener{

@Ghi đè
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_rsslist_overview);
}

// if the wizard generated an onCreateOptionsMenu you can delete
// it, not needed for this tutorial

@Ghi đè
public void onRssItemSelected(String link) {

}

}

activity_main.xml



android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="ngang" >

<>
android:id="@+id/listFragment"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="phù hợp với cha mẹ"
class="com.example.fragmentss.MyListFragment" >


android:layout_width="0px" android:layout_height="match_parent"
android:background="?android:attr/detailsElementBackground" />


MyListFragment 类

package com.example.fragmentss;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

public class MyListFragment extends Fragment {

@Ghi đè
công khai Xem trênCreateView(LayoutInflater inflater, ViewGroup container,
Gói savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_rsslist_overview,
container, false);
quay lại xem;
}

public void onClick2(View view) {
switch (view.getId()) {
case R.id.button2:
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);

DetailFragment newFragment = DetailFragment.newInstance();

ft.replace(R.id.details, newFragment, "mylistFragment");

// Start the animated transition.
ft.commit();
phá vỡ;
}
}
} ~

fragment _rssitem_detail.xml



android:layout_width="phù hợp với cha mẹ"
android:layout_height="phù hợp với cha mẹ"
android:orientation="dọc" >

<>
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Goto 2"
android:onClick="onClick1"/>


android:id="@+id/detailsText"
android:layout_width="wrap_content"
android:layout_height="phù hợp với cha mẹ"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_marginTop="20dip"
android:text="Frag 1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="30dip" />


fragment _rsslist_overview.xml



android:layout_width="phù hợp với cha mẹ"
android:layout_height="phù hợp với cha mẹ"
android:orientation="dọc" >

<>
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Goto 1"
android:onClick="onClick2" />


android:id="@+id/textView1"
android:layout_width="256dp"
android:layout_height="wrap_content"
android:layout_weight="0.18"
android:text="Frag 2"
android:textSize="30dip"/>


1 Câu trả lời

我猜想您要实现的功能可以很容易地通过 ViewPager hoàn thành

ViewPager 是一个自定义组件,它的引入是为了实现 fragment 之间轻松流畅的切换。 Android 文档有一个非常好且易于理解的示例来理解它的使用看看 http://developer.android.com/training/animation/screen-slide.html .你也可以看到已经回答过的类似问题 Example/Tutorial for ViewPager and FragmentsHow to use Android ViewPager?

关于Android - 滑动 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16256979/

26 4 0
太空宇宙
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com