相关疑难解决方法(0)

FragmentPagerAdapter和FragmentStatePagerAdapter有什么区别?

FragmentPagerAdapter和之间有什么区别FragmentStatePagerAdapter

关于FragmentPagerAdapterGoogle的指南说:

此版本的寻呼机最适合在有少量通常更多静态片段进行分页时使用,例如一组选项卡.用户访问的每个页面的片段将保留在内存中,但其视图层次结构可能在不可见时被销毁.这可能导致使用大量内存,因为片段实例可以保持任意数量的状态.对于较大的页面集,请考虑FragmentStatePagerAdapter.

关于FragmentStatePagerAdapter:

当存在大量页面时,此版本的寻呼机更有用,更像列表视图.当页面对用户不可见时,它们的整个片段可能被破坏,只保留该片段的保存状态.与FragmentPagerAdapter在页面之间切换时可能更多的开销相比,这允许寻呼机保持与每个被访问页面相关联的更少的存储器 .

所以我只有3个片段.但它们都是具有大量数据的独立模块.

Fragment1处理一些数据(用户输入)并通过活动传递给它Fragment2,这很简单ListFragment.Fragment3也是一个ListFragment.

所以我的问题是:我应该使用哪种适配器?FragmentPagerAdapter还是FragmentStatePagerAdapter

android android-fragments android-viewpager fragmentpageradapter fragmentstatepageradapter

357
推荐指数
5
解决办法
11万
查看次数

什么是AndroidX

我正在阅读关于Android的房间库.我看到他们改变包装androidandroidx.我不明白.请有人解释一下.

implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
Run Code Online (Sandbox Code Playgroud)

即使这也适用于android包装.

implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
Run Code Online (Sandbox Code Playgroud)
  • 需要什么来包装新的支持库androidx而不是android.
  • 用例和影响现有项目的因素.

android android-architecture-components android-jetpack androidx

204
推荐指数
8
解决办法
10万
查看次数

API 28(P)的Android设计支持库无法正常工作

我已经成功配置了android-P SDK环境.当我尝试使用android设计支持库时,我面临项目构建错误.项目配置是:

IDE:3.2 Canary 17目标API:28编译API:28

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.app.navigationpoc"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.1'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'

    implementation 'com.android.support:design:28.0.0-alpha3'
    implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
}
Run Code Online (Sandbox Code Playgroud)

并且构建失败的错误是:

清单合并失败:来自[androidx.core:core:1.0.0-alpha3] AndroidManifest.xml:22:18-86的属性应用程序@ appComponentFactory值=(androidx.core.app.CoreComponentFactory)也出现在[com.android] .support:support-compat:28.0.0-alpha3] AndroidManifest.xml:22:18-91 value =(android.support.v4.app.CoreComponentFactory).建议:在AndroidManifest.xml:6:5-40:19中添加'tools:replace ="android:appComponentFactory"'来覆盖.

android android-studio android-design-library android-9.0-pie

90
推荐指数
10
解决办法
15万
查看次数

getSupportFragmentManager()和getChildFragmentManager()有什么区别?

我的类继承了Fragment,这就是为什么它不能使用getSupportFragmentManager().我正在使用getChildFragmentManager,它显示错误 - IllegalArguementException:找不到id ...错误的视图.

任何指导将不胜感激.

调用AttachmentsListFragment的代码是

Bundle b = new Bundle();
b.putSerializable("AttachmentsList", msg.attachments);  
        AttachmentListFragment listfrag = new AttachmentListFragment(msg.attachments);
FragmentTransaction transaction = getFragmentManager().beginTransaction();       
transaction.add(R.id.attachmentslistcontainer, listfrag);
transaction.addToBackStack(null);
transaction.commit();
Run Code Online (Sandbox Code Playgroud)

attachmentslayout.xml是

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/attachmentslistcontainer"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textViewAttachmentHeader"
        style="@style/Normal.Header.Toolbar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/list_separator_background"
        android:ellipsize="end"
        android:gravity="center"
        android:maxLines="2"
        android:text="@string/attachments_header"
        android:textColor="#FFFFFFFF"
        android:textSize="22sp"
        android:textStyle="bold"
        android:visibility="visible" />

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </ListView>

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

AttachmentsListFragment.java

public class AttachmentListFragment extends ListFragment implements IAttachmentsData {

    ArrayList<Attachments> items = null;
    Integer cellLayoutID;
    Integer index;

    public AttachmentListFragment() {

    } …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-listfragment

64
推荐指数
3
解决办法
4万
查看次数

androidSu+中的getSupportFragmentManager()与getFragmentManager()

在android.support.v4.app.FragmentManager的文档中:

"静态库支持版本的框架的FragmentManager.用于编写在Android 3.0之前的平台上运行的应用程序.在Android 3.0或更高版本上运行时,仍然使用此实现;它不会尝试切换到框架的实现.请参阅用于类概述的框架SDK文档."

那么,我是否需要在运行时进行检查并使用相应的FragmentManager来运行应用程序的Android版本?ie如果在android 3.0+而不是getSupportFragmentManager()上调用getFragmentManager()

android actionbarsherlock

7
推荐指数
2
解决办法
2万
查看次数