我正在寻找停止在Viewpager中预加载页面的示例源代码。通常,android viewpager会自动加载下一页和上一页。我的目标是使用viewpager,并且我希望在用户可见时在视图(页面中存在)上显示动画。基本上是继续上一篇 文章。
如果您能给我任何可行的例子(完整的代码),那就太好了。我发现了很多,但没有找到任何可行的实现。谢谢你的帮助。关于比斯瓦吉特
android android-fragments android-viewpager android-pageradapter
我试图在一个片段中调用一个库,但是不知道如何在一个片段中设置它我已经在主要活动中完成了但是我在我的片段中设置setContentView时遇到错误编译依赖
compile 'com.github.medyo:android-about-page:1.0.2'
Run Code Online (Sandbox Code Playgroud)
我的片段内容视图
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_navigation, container, false);
Element versionElement = new Element();
versionElement.setTitle("Version 6.2");
Element adsElement = new Element();
adsElement.setTitle("Advertise with us");
View aboutPage = new AboutPage(getActivity())
.isRTL(false)
.addItem(versionElement)
.addItem(adsElement)
.addGroup("Connect with us")
.addEmail("elmehdi.sakout@gmail.com")
.addFacebook("the.medy")
.addTwitter("medyo80")
.addYoutube("UCdPQtdWIsg7_pi4mrRu46vA")
.addPlayStore("com.ideashower.readitlater.pro")
.addInstagram("medyo80")
.addGitHub("medyo")
.create();
setContentView(aboutPage);
return rootView;
}
Run Code Online (Sandbox Code Playgroud)
我在倒数第二行得到错误如何解决这个问题.以下库可在api 20+库https://github.com/medyo/android-about-page中使用
我用viewPager和TabLayout创建了我的布局:
public class HomeFragment extends Fragment
{
public static TabLayout tabLayout;
public static ViewPager viewPager;
public static int int_items = 3 ;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View inflatedView = inflater.inflate(R.layout.fragment_home, container,false);
viewPager = (ViewPager) inflatedView.findViewById(R.id.viewpager);
int [] drawables = {R.drawable.home,R.drawable.street,R.drawable.map};
Bundle bundle = new Bundle();
final SearchFragment searchFragment = new SearchFragment();
final CardFragment cardFragment = new CardFragment();
final MapFragment mapFragment = new MapFragment();
viewPager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager())
{
public Fragment getItem(int position)
{
if(position == 0)
return …Run Code Online (Sandbox Code Playgroud) 我在我的android studio项目中使用ButterKnife 8.0.1.下面是我的gradle文件和片段类的片段.我无法在按钮点击中看到Toast消息.但是如果我使用onCLicklistener,我可以看到Toast.
请帮我看看我做错了什么我被卡住了
我的Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "tdd.serveroverload.com.tdd"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.jakewharton:butterknife:8.0.1'
}
Run Code Online (Sandbox Code Playgroud)
片段类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View calcView = inflater.inflate(R.layout.content_main, container, …Run Code Online (Sandbox Code Playgroud) 问题:我使用EventBus的greenrobot通过一些事件。不幸的是,对于在两个之间fragments不传递数据的情况,它对我有用。因此,该事件不会被触发。
问题:我会误解这个概念吗?还是我的代码有错误?
注意:两个片段在发送事件时都存在。一个fragment是父母,另一个是孩子以显示详细信息。
详细片段:
public class DetailFragment extends Fragment {
(...)
refreshButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
EventBus.getDefault().post(new IntentRefresh());
}
});
(...)
}
Run Code Online (Sandbox Code Playgroud)
EventBus类别:
public class IntentRefresh {
public IntentRefresh (){}
public void refreshParent() {
}
}
Run Code Online (Sandbox Code Playgroud)
父片段:
public class ParentFragment extends Fragment {
(...)
@Override
public void onPause() {
super.onPause();
EventBus.getDefault().unregister(this);
}
@Override
public void onResume() {
super.onResume();
EventBus.getDefault().register(this);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void …Run Code Online (Sandbox Code Playgroud) 我正在尝试从活动中删除操作栏.
我已经完成了以下操作,但它仍然将Action栏保留在我的Activity上
public class MyActivity extends AppCompatActivity{ .. }
Run Code Online (Sandbox Code Playgroud)
布局
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".TM.TMActivity"
style="@style/AppTheme.NoActionBar"
>
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/AppTheme.NoActionBar"
/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
Style.xml
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud) android android-appcompat android-layout android-fragments android-activity
我正在制作一个应用程序,长按后将复制列表视图上的文本.我在listview中创建了一个字符串数组,现在我想在片段中实现长按事件.就像我长按列表项目1时一样,它应该被复制到剪贴板中.我该如何实现它?
OneFragment.java
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.dragedy.kickasshumor.R;
public class OneFragment extends Fragment{
public OneFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_one, container, false);
}
}
Run Code Online (Sandbox Code Playgroud)
FragmentOne.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/list"
android:id="@+id/listView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
strings.xml中
<resources>
<string-array name="list">
<item>Item 1</item> …Run Code Online (Sandbox Code Playgroud) 我想知道是否有一个托管静态引用Fragment或者Activity是否可以?通过托管我的意思是在相关的生命周期回调上释放静态引用.请考虑以下代码:
public class StaticReferencedFragment extends Fragment {
public static StaticReferencedFragment instance;
public StaticReferencedFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_static_referenced, container, false);
}
@Override
public void onStart() {
super.onStart();
instance = this;
}
@Override
public void onStop() {
super.onStop();
instance = null;
}
}
Run Code Online (Sandbox Code Playgroud)
我是否有冒泄漏Fragment/Activity物体的风险?
我在onCreateView()Fragment中夸大了版面。此布局包含一个自定义视图。现在文档的onActivityCreated()说,这是“ 片段的活动已创建时调用这个片段的视图层次实例化 ”。这意味着布局已膨胀,并且布局中的视图之前已创建onActivityCreated()。
那么,这是否意味着视图的onLayout(),onSizeChanged()和onDraw()方法之前调用onActivityCreated()?
android ondraw android-fragments android-canvas android-view
我正在使用一个片段,编译器不会抛出任何错误.但是当我按下我创建了一个监听器的指定按钮时,该应用程序崩溃了!logcat引用了null object reference这部分代码......
private ImageView i;
private String key = null;
private ArrayList<String> lst = new ArrayList();
private OnClickListener lstn = new OnClickListener() {
public void onClick(View v)
{
EditText et1 = (EditText) v.findViewById(R.id.editText1);
profilname = et1.getText().toString();
new getPbLink().execute(new String[]{profilname});
}
};
private OnClickListener lstn1 = new OnClickListener() {
public void onClick(View v)
{
if (pb == null)
{
Toast.makeText(getActivity(),"nodp", 0)
.show();
} else
{
SaveImage(pb);
Toast.makeText(getActivity(), "saved", 0)
.show();
}
}
};
Run Code Online (Sandbox Code Playgroud)
该怎么办?logcat -
Process: com.nav.drawer, PID: …Run Code Online (Sandbox Code Playgroud) android ×10
android-view ×1
butterknife ×1
callback ×1
event-bus ×1
listview ×1
memory-leaks ×1
ondraw ×1