Questions tagged «android»

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

16
嵌套片段在过渡动画期间消失
这里的情景:活动包含片段A,又使用getChildFragmentManager()添加片段A1,并A2在其onCreate像这样: getChildFragmentManager() .beginTransaction() .replace(R.id.fragmentOneHolder, new FragmentA1()) .replace(R.id.fragmentTwoHolder, new FragmentA2()) .commit() 到目前为止,一切都很好,一切正常。 然后,我们在Activity中运行以下事务: getSupportFragmentManager() .beginTransaction() .setCustomAnimations(anim1, anim2, anim1, anim2) .replace(R.id.fragmentHolder, new FragmentB()) .addToBackStack(null) .commit() 在过渡期间,enter片段的动画B正确运行,但片段A1和A2完全消失。当我们使用“后退”按钮还原事务时,它们会正确初始化并在popEnter动画过程中正常显示。 在我的简短测试中,它变得很奇怪-如果我为子片段设置动画(请参见下文),则exit在添加片段时动画会间歇性地运行B getChildFragmentManager() .beginTransaction() .setCustomAnimations(enter, exit) .replace(R.id.fragmentOneHolder, new FragmentA1()) .replace(R.id.fragmentTwoHolder, new FragmentA2()) .commit() 我要实现的效果很简单-我想运行片段(anim2)上的exit(或应该是popExit?)动画,A从而对整个容器(包括其嵌套的子代)进行动画处理。 有什么方法可以实现? 编辑:请在这里找到一个测试用例 Edit2:感谢@StevenByle促使我继续尝试使用静态动画。显然,您可以基于每个操作设置动画(不是整个事务的全局动画),这意味着子级可以具有不确定的静态动画集,而其父级可以具有不同的动画,并且整个事情可以在一个事务中完成。请参阅下面的讨论和更新的测试用例项目。

1
Android:使用XML为切换按钮指定两个不同的图像
我正在尝试覆盖默认ToggleButton外观。这是定义的XML ToggleButton: <ToggleButton android:id="@+id/FollowAndCenterButton" android:layout_width="30px" android:layout_height="30px" android:textOn="" android:textOff="" android:layout_alignParentLeft="true" android:layout_marginLeft="5px" android:layout_marginTop="5px" android:background="@drawable/locate_me"/> 现在,我们有两个要用于单击/未单击状态的30 x 30图标。现在,我们有一些代码,可以根据状态以编程方式更改背景图标: centeredOnLocation.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (centeredOnLocation.isChecked()) { centeredOnLocation.setBackgroundDrawable(getResources().getDrawable(R.drawable.locate_me_on)); } else { centeredOnLocation.setBackgroundDrawable(getResources().getDrawable(R.drawable.locate_me)); } } }); 显然,我正在寻找一种更好的方法来做到这一点。我试图为背景图片创建一个选择器,该选择器将在状态之间自动切换: <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/locate_me" /> <!-- default --> <item android:state_checked="true" android:drawable="@drawable/locate_me_on" /> <!-- pressed --> …


5
片段onCreateView和onActivityCreated调用了两次
我正在使用Android 4.0 ICS和片段开发应用程序。 考虑一下ICS 4.0.3(API级别15)API的演示示例应用程序中的以下修改示例: public class FragmentTabs extends Activity { private static final String TAG = FragmentTabs.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final ActionBar bar = getActionBar(); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE); bar.addTab(bar.newTab() .setText("Simple") .setTabListener(new TabListener<SimpleFragment>( this, "mysimple", SimpleFragment.class))); if (savedInstanceState != null) { bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0)); Log.d(TAG, "FragmentTabs.onCreate tab: …

15
Android中的相机方向问题
我正在构建一个使用相机拍照的应用程序。这是我执行此操作的源代码: File file = new File(Environment.getExternalStorageDirectory(), imageFileName); imageFilePath = file.getPath(); Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); //Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intent, ACTIVITY_NATIVE_CAMERA_AQUIRE); 在onActivityResult()方法上,我BitmapFactory.decodeStream()用来拾取图像。 当我在Nexus One上运行我的应用程序时,它运行良好。但是,当我在Samsung Galaxy S或HTC Inspire 4G上运行时,图像的方向不正确。 使用人像模式拍摄时,真实图像(保存在SD卡上)始终旋转90度。 拍摄后的图像预览--------- SD卡上的真实图像 使用风景模式拍摄时,一切都很好。 拍摄后的图像预览--------- SD卡上的真实图像

4
Android Quick Actions UI模式
我对合并称为“快速操作”的Android UI模式感兴趣。基本上,这是一个上下文菜单,不会掩盖正在执行的数据。我想实现此功能,但是找不到一些示例代码或API来帮助我。 请注意,YouTube视频http://www.youtube.com/watch?v=M1ZBjlCRfz0#t=15m20s中讨论了这种用户界面模式。 是否有人对此有实现,还是知道Google将其添加到应用程序的标准是什么?
100 android 

16
EditText,将重点放在外部触摸上
我的布局包含ListView,SurfaceView和EditText。当我单击时EditText,它会收到焦点,并且会弹出屏幕键盘。当我点击以外的某个地方时EditText,它仍然具有焦点(应该没有)。我想我可以OnTouchListener在布局中的其他视图上设置,并手动清除EditText的焦点。但是似乎太客气了... 在其他布局中,我也有相同的情况-列表视图包含不同类型的项目,其中一些包含EditText。它们的行为就像我上面写的一样。 任务是EditText当用户触摸其外部的东西时使其失去焦点。 我在这里看到过类似的问题,但是还没有找到解决方案...

7
如果大于1行,如何在TextView上显示椭圆?
我有以下布局不起作用: <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:id="@+id/experienceLayout" android:background="#ffffff" android:layout_height="match_parent" android:paddingLeft="6dp" android:paddingRight="6dp" android:paddingBottom="6dp" android:paddingTop="6dp"> <TextView android:layout_weight="1" android:id="@+id/experienceLabel" android:text="Experience" android:layout_height="wrap_content" android:textColor="#000000" android:layout_width="wrap_content" android:textStyle="bold"> </TextView> <TextView android:id="@+id/experienceTextView" android:text="TextView" android:layout_height="wrap_content" android:textColor="#000000" android:layout_width="wrap_content" android:ellipsize="end" android:lines="1" android:maxLines="1" android:singleLine="true" android:fadeScrollbars="false"> </TextView> </LinearLayout>

9
使LinearLayout像按钮一样
我有一个LinearLayout样式类似于的样式button,其中包含一些text / ImageView元素。我想使整个LinearLayout动作像a一样button,特别是要赋予它在a中定义的状态,以便在按下时具有不同的背景。 有没有比ImageButton确定整个Layout的大小和绝对定位更好的方法?

15
未定义对__android_log_print的引用
我的make文件怎么了? Android.mk LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := foo LOCAL_SRC_FILES := foo.c LOCAL_EXPORT_LDLIBS := -llog include $(BUILD_SHARED_LIBRARY) foo.c #include <string.h> #include <jni.h> #include <android/log.h> #define LOG_TAG "foo" #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) void test() { LOGI("test"); } ndk构建 foo.c:9: undefined reference to `__android_log_print'

10
从另一个活动中完成一个活动
我想从另一个活动中完成一个活动,例如: 在活动[A]中,单击按钮时,我在不完成活动[A]的情况下调用活动[B]。 现在在活动[B]中,有两个按钮,“ 新建”和“ 修改”。当用户单击“修改”时,从堆栈中弹出活动[A],并勾选所有选项。 但是当用户单击“ 新建”时活动[B]中的“按钮时,我将不得不从堆栈中完成活动[A],然后再次将该活动[A]重新加载到堆栈中。 我正在尝试,但是无法完成堆栈中的活动[A] ...我该怎么做? 我将代码用作: 从活动[A]: Intent GotoB = new Intent(A.this,B.class); startActivityForResult(GotoB,1); 同一活动中的另一种方法 public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == 1) { if (resultCode == 1) { Intent i = getIntent(); overridePendingTransition(0, 0); i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); finish(); overridePendingTransition(0, 0); startActivity(i); } } …

11
究竟如何使用Notification.Builder
我发现我正在使用不推荐使用的方法进行通知(notification.setLatestEventInfo()) 它说要使用Notification.Builder。 如何使用? 当我尝试创建一个新实例时,它告诉我: Notification.Builder cannot be resolved to a type



5
在Android中叠加两个图像以设置一个imageview
我正在尝试在应用程序中叠加两个图像,但是它们似乎在我的canvas.setBitmap()行崩溃了。我究竟做错了什么? private void test() { Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.t); Bitmap mBitmap2 = BitmapFactory.decodeResource(getResources(), R.drawable.tt); Bitmap bmOverlay = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), mBitmap.getConfig()); Canvas canvas = new Canvas(); canvas.setBitmap(bmOverlay); canvas.drawBitmap(mBitmap, new Matrix(), null); canvas.drawBitmap(mBitmap2, new Matrix(), null); testimage.setImageBitmap(bmOverlay); }
100 android  image 

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.