Questions tagged «android»

Android是Google的移动操作系统,用于对数字设备(智能手机,平板电脑,汽车,电视,Wear,Glass和IoT)进行编程或开发。对于与Android相关的主题,请使用特定于Android的标签,例如android-intent,android-activity,android-adapter等。对于与开发或编程无关但与Android框架相关的问题,请使用以下链接:https:// android.stackexchange.com。

3
在android中命名我的应用程序
我认为我越来越老了,因为我坚信要为您的应用程序起一个名字,您必须填写清单的这一部分: <application android:icon="@drawable/icon" android:label="MyApplicationName"> 但是由于我不明白的原因,我的应用程序获得了我的第一个活动的名称,在该活动中我加载数据,因此,它被称为“加载”,在清单中的定义如下: <activity android:name="AccueilSplash" android:label="Loading"> 知道为什么吗?

5
SurfaceHolder回调与Activity生命周期如何相关?
我一直在尝试实现需要在表面上预览相机的应用程序。正如我所看到的,活动和表面生命周期都包含以下状态: 首次启动活动时: onResume()->onSurfaceCreated()->onSurfaceChanged() 当我离开活动时: onPause()->onSurfaceDestroyed() 在此方案中,我可以做相应的像在开/释放摄像头和启动/停止预览电话onPause/onResume和onSurfaceCreated()/onSurfaceDestroyed()。 除非我锁定屏幕,否则它工作正常。当我启动该应用程序时,然后锁定屏幕并稍后解锁,我看到: onPause()-屏幕锁定后没有其他内容-然后是onResume()解锁后-之后没有任何表面回调。实际上,onResume()是在按下电源按钮并打开屏幕后调用的,但是锁定屏幕仍处于活动状态,因此,在活动可见之前就已经调用了。 使用此方案,解锁后会出现黑屏,并且不会调用任何表面回调。 这是一个代码片段,它不涉及相机的实际工作,而是SurfaceHolder回调。即使在我的手机上使用此代码,也会出现上述问题(按“返回”按钮时会以正常顺序调用回调,但锁定屏幕时会丢失回调): class Preview extends SurfaceView implements SurfaceHolder.Callback { private static final String tag= "Preview"; public Preview(Context context) { super(context); Log.d(tag, "Preview()"); SurfaceHolder holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { Log.d(tag, "surfaceCreated"); } public void surfaceDestroyed(SurfaceHolder holder) { …

7
Android-未针对API 23调用onAttach(Context)
我已经将SDK更新到最新版本(API 23),onAttach(Activity)不建议使用分段方法。因此,我现在使用的不是使用该方法,onAttach(Context)而是在生命周期中不调用此方法。该活动是AppCompatActivityv7的实例,而该片段是Fragment(android.app.Fragment)类的实例。 有任何想法如何使onAttachAPI 23正常工作吗? 解 我找到了一些可以帮助您理解和解决此问题的答案: 如前所述,我正在使用支持v7中的活动(AppCompatActivity)和android.app中的片段。 为了显示片段,我在活动中使用getFragmentManager方法获取片段管理器,因此片段管理器是android.app->中FragmentManager的实例,这就是问题所在 如果您在具有API 23的设备上运行该应用程序(我已经在AS Emulator上运行了该应用程序),则会看到将调用onAttach(Context)方法。在FragmentManager显示片段的过程中,在特定时刻调用onAttach(..)方法。使用getFragmentManager(),您将获得可在该设备上运行的Android版本的片段管理器实例(例如API 22、23)。如果应用程序在API <23的设备上运行,则onAttach(Context)方法不可用,片段管理器不知道API 23中存在onAttach(Context)方法,因此未调用它对于API <23->,针对此类问题的解决方案是使用支持库中的FragmentManager。 解决方案: 使用getSupportFragmentManager()将强制您使用支持库中的片段。因此,第一个解决方案是用support lib中的片段替换所有片段,并使用getSupportFragmentManager()。 我已经实现的解决方案是处理2种可能性(1.该应用程序在API <23的设备上运行,该应用程序在API> = 23的设备上运行)。 不久,在我的实现中,我为项目中的所有片段提供了一个基类,并在其中添加了以下代码: /* * onAttach(Context) is not called on pre API 23 versions of Android and onAttach(Activity) is deprecated * Use onAttachToContext instead */ @TargetApi(23) @Override public final void …


7
Android ImageView:适合宽度
我下载图片并将其动态设置为屏幕背景Imageview。我尝试过ScaleType缩放图像。 如果图像高度大于宽度,则大ScaleTypes fitStart,fitEnd并且fitCenter不工作。Android会缩小照片并根据高度进行调整,但我看到一些多余的空白作为宽度的一部分。 我想根据宽度缩小照片,使其适合宽度,并且我不在乎是否有一些额外的空白作为高度的一部分,或者如果高度过长,可以将其超出视野范围(如果可能的话?)。 ScaleType.XY缩放照片并适合其中的所有内容,ImageView并且不在乎图像的高度/重量比。 <ImageView android:id="@+id/background" android:layout_width="match_parent" android:layout_height="match_parent" android:adjustViewBounds="true" android:scaleType="fitStart" />

9
ImageView是具有动态宽度的正方形吗?
我有一个带有ImageViews的GridView。我每行有3个。我可以使用WRAP_CONTENT和scaleType = CENTER_CROP正确设置宽度,但是我不知道如何将ImageView的大小设置为正方形。这是我到目前为止所做的,除了高度,它是“静态的”,似乎还可以: imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setLayoutParams(new GridView.LayoutParams(GridView.LayoutParams.WRAP_CONTENT, 300)); 我正在适配器内做。

9
FragmentTransaction动画在顶部滑动
我正在尝试使用FragmentTransaction.setCustomAnimations实现以下效果。 片段A正在显示 用片段B替换片段A。片段A在替换期间应保持可见。片段B应该从右侧滑入。片段B应滑入片段A的顶部。 在动画设置中获取幻灯片没有问题。我的问题是,我无法弄清楚如何使片段A停留在原处并在动画幻灯片运行时位于片段B之下。不管我做什么,片段A似乎都在上面。 我该如何实现? 这是FragmentTransaction代码: FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.setCustomAnimations(R.anim.slide_in_right, R.anim.nothing, R.anim.nothing, R.anim.slide_out_right); ft.replace(R.id.fragment_content, fragment, name); ft.addToBackStack(name); ft.commit(); 如您所见,我为“ out”动画定义了一个动画R.anim.nothing,因为我实际上不希望Fragment A做任何事情,而不仅仅是在事务处理期间停留在原处。 以下是动画资源: slide_in_right.xml <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="@android:integer/config_mediumAnimTime" android:fromXDelta="100%p" android:toXDelta="0" android:zAdjustment="top" /> 没有.xml <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="@android:integer/config_mediumAnimTime" android:fromAlpha="1.0" android:toAlpha="1.0" android:zAdjustment="bottom" />

11
在返回按钮上的片段中,活动为空
我有一个活动,并且很多片段都膨胀了 FrameLayout <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> 示例:mainActivity>任何片段(按返回按​​钮)>活动为空白。 在onCreate中: layout = (FrameLayout)findViewById(R.id.content_frame); layout.setVisibility(View.GONE); 当我开始片段时: FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.content_frame, profileFragment); ft.addToBackStack(null); ft.commit(); layout.setVisibility(View.VISIBLE); 我想我需要GONE再次按一下frameLayout的可见性,但是我该怎么做呢? 我尝试onBackPressed并设置,layout.setVisibility(View.GONE);但是无法直接浏览片段,因为我直接进入主页。


18
如何从Firebase Android获取所有子列表
我想要Android中Firebase的所有子列表。 我已经实现了此代码,但无法正常工作。 mFirebaseRef = new Firebase(FIREBASE_URL); mFirebaseRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { List<String> td = (ArrayList<String>) dataSnapshot.getValue(); //notifyDataSetChanged(); } @Override public void onCancelled(FirebaseError firebaseError) { } });

6
如何使EditText框高度展开
这是我的布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <EditText android:id="@+id/etTweetReview" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:ems="10" android:hint="Discuss up to 140 characters" android:imeOptions="actionDone" android:inputType="textCapSentences" android:lines="2" android:maxLength="140" android:paddingBottom="10dp" android:singleLine="false" /> <Button android:id="@+id/theReviewBarButton" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginBottom="5dp" android:text="Submit Review" android:textSize="22sp" /> <Spinner android:id="@+id/spinnerSort" android:layout_width="120dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" /> <ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/android:list" …

5
如何获取在XML布局中添加的片段
我有一个包含以下片段的布局: <fragment android:id="@+id/mainImagesList" android:name="com.guc.project.ImagesList" android:layout_width="match_parent" android:layout_height="62dp" android:layout_below="@+id/addimagebutton" android:layout_weight="1" android:paddingTop="55dp" /> 现在,我需要获取此片段并将其投射,以便可以对其进行操作并显示更新。我该怎么办? 编辑:我想我已经设法获取片段,但是当我更改一些变量时,更改不会出现!
73 android  fragment 

14
无法解决:com.google.firebase:firebase-core:16.0.1
我正在尝试将Firebase云存储添加到我的应用程序。以下是应用程序build.gradle。但它说:无法解决:com.google.firebase:firebase-core:16.0.1。为什么?依赖项中根本没有firebase-core。 apply plugin: 'com.android.application' android { compileSdkVersion 27 defaultConfig { applicationId "com.louise.udacity.mydict" minSdkVersion 15 targetSdkVersion 27 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(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support.constraint:constraint-layout:1.1.0' implementation 'com.google.firebase:firebase-storage:16.0.1' implementation 'com.google.firebase:firebase-auth:16.0.1' …

11
如何将快速卷轴添加到RecyclerView
背景 在ListView上,您可以使用快速滚动器,该滚动器允许您拖动滚动条以轻松滚动至所需位置(使用fastScrollEnabled属性) 连同“ SectionIndexer ”类以及可选的一些属性一起,您可能会在使用此滚动条时看到一个漂亮的弹出窗口(此处链接)。 这样的事情会显示在通讯录应用程序中,以便您可以轻松滚动至特定字母。 问题 RecyclerView似乎没有任何这些。甚至没有快速滚动。 问题 如何为RecyclerView添加快速滚动器功能?

6
使用Proguard模糊处理时,Gson EnumTypeAdapter中出现AssertionError
我的项目在序列化/反序列化期间实现了一个TypeAdapterin Gson,以保留对象的多态状态。无论如何,该项目在开发测试期间运行良好,但是当通过proguard混淆发布并进行测试时,它只是崩溃。 03-21 10:06:53.632: E/AndroidRuntime(12441): FATAL EXCEPTION: main 03-21 10:06:53.632: E/AndroidRuntime(12441): java.lang.AssertionError 03-21 10:06:53.632: E/AndroidRuntime(12441): at com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter.<init>(SourceFile:724) 03-21 10:06:53.632: E/AndroidRuntime(12441): at com.google.gson.internal.bind.TypeAdapters$26.create(SourceFile:753) 03-21 10:06:53.632: E/AndroidRuntime(12441): at com.google.gson.Gson.getAdapter(SourceFile:353) 03-21 10:06:53.632: E/AndroidRuntime(12441): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(SourceFile:82) 03-21 10:06:53.632: E/AndroidRuntime(12441): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(SourceFile:81) 03-21 10:06:53.632: E/AndroidRuntime(12441): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(SourceFile:118) 03-21 10:06:53.632: E/AndroidRuntime(12441): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(SourceFile:72) 03-21 10:06:53.632: E/AndroidRuntime(12441): …
73 android  gson  proguard 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.