我想知道为什么不在 android:configChanges="keyboardHidden|orientation"每个(几乎每个;))活动中使用?
产品:
不太好:
坏:
但如果我们不使用不同的布局,为什么不呢?
是否可以 在TextView中添加?有没有人实现类似的功能?
我想在TextView中拥有不可破坏的空间.
源代码可在此处获取:https://github.com/novemberox/NavigationTest此示例的修改版本:http://developer.android.com/training/implementing-navigation/ancestral.html
我有三个活动:
Main Activity 只是申请的主要入口Category Activity 它是详细活动的父级Detail ActivityMain Activity有打开的按钮Category Activity和Detail Activity.
Category Activty只有一个按钮打开Detail Activity.最后Detail Activity,它显示了一些文本,并具有模拟点击ActionBar的向上按钮.
我的"点击"路径是:
这是预期的流程,并且在Jelly Bean(在Galaxy Nexus 4.1.1和模拟器4.2 Google exppack上测试)之前,它在每个Android上运行良好.它甚至可以在ICS上运行.我正在使用支持库和类似NavUtils和TaskStackBuilder的类,就像我在开始时指出的示例一样.
在JB上单击"向上按钮"时,它返回到主活动状态,状态恢复正常.我查看了支持库的源代码,我看到该NavUtils.navigateUpTo方法调用本机JB代码Activity#navigateUpTo.我尝试了两个NavUtils#navigateUpTo()并且NavUtils.navigateUpFromSameTask()具有相同的不满意结果.
你有什么建议要做这个好流程吗?
一些设备即.Galaxy Tablet 10.1只能发短信,但无法拨打电话.像Asus Transformer这样的其他设备甚至没有SIM卡.
如何检测设备是否可以拨打电话?如何检测设备是否可以发送短信?
我进入了attrs.xml
<resources>
<!-- theme specific colors -->
<attr format="reference|color" name="foreground" />
<attr format="reference|color" name="background" />
</resources>
Run Code Online (Sandbox Code Playgroud)
然后在theme.xml中
<style name="MyTheme" parent="android:Theme.Black">
<item name="android:windowNoTitle">true</item>
<item name="foreground">#0000FF</item>
<item name="background">#00FF00</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我还创建了名为forground_to_background.xml的颜色选择器
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="?background"/> <!-- pressed -->
<item android:state_focused="true" android:color="?background"/> <!-- focused -->
<item android:color="?foreground"/> <!-- default -->
</selector>
Run Code Online (Sandbox Code Playgroud)
现在我想在TextView中一起使用它:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/forground_to_background" />
Run Code Online (Sandbox Code Playgroud)
不幸的是它不起作用.我没有漂亮的绿蓝色,只有一种颜色 - 红色.TextView始终为红色.当我将TextView更改为使用"?foreground"时,颜色会发生变化.此外,当我将颜色选择器从"?xxxx"更改为硬编码值时,"#00f"颜色开始起作用.
哪里有问题?我究竟做错了什么?
编辑: 我认为它是问题/错误的重复选择器资源可以使用样式中定义的颜色吗?
Edit2: 此外,当我尝试在ListView应用程序中使用此TextView时崩溃.它无法解析XML.
这个ImageView有一些奇怪的东西,在缩小大图像之后还有"自由空间".
<?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="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/bb"
android:scaleType="fitStart" />
<TextView
android:id="@+id/textMainBoxTitle"
android:text="some text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
一些屏幕:
Eclipse:
eclipse http://img560.imageshack.us/img560/6218/eclipse.png
模拟器:
模拟器http://img600.imageshack.us/img600/3023/simulator.png
原始图片:
原创http://www.janissary.eu/img/obraz.jpg
为什么我会在图像之后获得空间?
我正试图在全屏播放html中的视频.当我在视频方法中单击全屏按钮onShowCustomView被触发时.这是我的实现:
public void onShowCustomView(View view, CustomViewCallback callback) {
super.onShowCustomView(view, callback);
if (view instanceof FrameLayout) {
customComponenet.addView(view, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT,
Gravity.CENTER));
customComponenet.setVisibility(View.VISIBLE);
}
}
Run Code Online (Sandbox Code Playgroud)
customComponenet是将FrameLayout置于当前布局之上的位置.Wideo打得很好,它是可见的,一切接缝都可以,但它会抛出:
08-27 22:16:07.520: ERROR/AndroidRuntime(7235): FATAL EXCEPTION: main
08-27 22:16:07.520: ERROR/AndroidRuntime(7235): java.lang.NullPointerException
08-27 22:16:07.520: ERROR/AndroidRuntime(7235): at android.webkit.HTML5VideoFullScreen.switchProgressView(HTML5VideoFullScreen.java:320)
08-27 22:16:07.520: ERROR/AndroidRuntime(7235): at android.webkit.HTML5VideoView.setPlayerBuffering(HTML5VideoView.java:319)
08-27 22:16:07.520: ERROR/AndroidRuntime(7235): at android.webkit.HTML5VideoView.start(HTML5VideoView.java:85)
08-27 22:16:07.520: ERROR/AndroidRuntime(7235): at android.webkit.HTML5VideoViewProxy$VideoPlayer.onPrepared(HTML5VideoViewProxy.java:257)
08-27 22:16:07.520: ERROR/AndroidRuntime(7235): at android.webkit.HTML5VideoViewProxy.onPrepared(HTML5VideoViewProxy.java:278)
08-27 22:16:07.520: ERROR/AndroidRuntime(7235): at android.webkit.HTML5VideoView.onPrepared(HTML5VideoView.java:265)
08-27 22:16:07.520: ERROR/AndroidRuntime(7235): at android.webkit.HTML5VideoFullScreen.onPrepared(HTML5VideoFullScreen.java:164)
08-27 22:16:07.520: ERROR/AndroidRuntime(7235): at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:1456)
08-27 22:16:07.520: ERROR/AndroidRuntime(7235): at android.os.Handler.dispatchMessage(Handler.java:99) …Run Code Online (Sandbox Code Playgroud) 在如何显示之前,如何将scrollview滚动设置为x像素?
在ScrollView中我有一些视图,我知道它将填充屏幕.我可以滚动来说第二个视图,以便在活动开始时第一个视图不可见吗?
现在我有这样的感觉,但我觉得它并不完美,有时,我看到第一个View,然后滚动到第二个
@Override
public void onGlobalLayout() {
if (mHorizontalScrollView.getChildCount() > 0 && mHorizontalScrollView.getChildAt(0).getWidth() > mScreenWidth) {
hsv.scrollTo(100, 0);
}
}
Run Code Online (Sandbox Code Playgroud)
编辑!!
第二次尝试是使用http://developer.android.com/reference/android/view/ViewTreeObserver.OnPreDrawListener.html而不是http://developer.android.com/reference/android/view/ViewTreeObserver.OnGlobalLayoutListener.html
In OnPreDrawListener我们可以读到At this point, all views in the tree have been measured and given a frame. Clients can use this to adjust their scroll bounds or even to request a new layout before drawing occurs.这一点,所以基本上我们应该调整滚动.所以我创建了:
@Override
public boolean onPreDraw() {
if (hsv.getChildCount() > 0 && hsv.getChildAt(0).getWidth() > mScreenWidth) {
hsv.scrollTo(100, 0); …Run Code Online (Sandbox Code Playgroud) 我想知道我是否可以更改设备,它决定应该选择哪个布局或者应该选择/缩放哪个图形.此更改只会影响我的应用程序.我能以某种方式设置DPI吗?
我之所以这样做的原因是这款手机:http://www.gsmarena.com/samsung_p1000_galaxy_tab-3370.php它的DPI值非常差240DPI,而它只有170PPI,应该被认为是160DPI设备.我有相当大的图形布局 - 大看起来很棒的mdpi,但在hdpi他们不适合,他们只是大.
也许你有另一种解决方案而不是改变设备DPI?
在api level 4(android 1.6)上拍照后使用:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File photo = new File(Environment.getExternalStorageDirectory(), "NewPic.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
imageUri = Uri.fromFile(photo);
startActivityForResult(intent, TAKE_PICTURE);
Run Code Online (Sandbox Code Playgroud)
我想查看我的所有照片缩略图,但没有我的最后一张照片缩略图.它在android 2.1上完美运行.
如果我通过USB将设备连接到PC,则扫描完成后会出现断开连接的文件.那么我应该如何开始索引呢?
我试过了
mScanner = new MediaScannerConnection(getApplicationContext(), this);
mScanner.connect();
mScanner.scanFile(imageUri.getEncodedPath(), "*/*");
Run Code Online (Sandbox Code Playgroud)
并以此结束:
02-24 17:13:54.678: DEBUG/MediaScannerService(1320): IMediaScannerService.scanFile: /sdcard/NewPic2222.jpg mimeType: */*
02-24 17:13:54.688: VERBOSE/MediaProvider(1320): /sdcard volume ID: 1149784819
02-24 17:13:54.688: VERBOSE/MediaProvider(1320): key exists
Run Code Online (Sandbox Code Playgroud)
稍后编辑
在其他活动中,我有这样的感觉
mCursorThumbnails = MediaStore.Images.Thumbnails.queryMiniThumbnails(mContentResolver, MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, MediaStore.Images.Thumbnails.MINI_KIND, projection);
mCursorImages = MediaStore.Images.Media.query(mContentResolver, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection);
Run Code Online (Sandbox Code Playgroud)
当我检查第一个值的计数时,我有13个元素,而在第二个我有14个.所以图像已经添加到mediascanner,但是OS没有为它生成缩略图.那么我该如何要求操作系统创建一个呢?
我想存储QHash从一个类继承的元素.所以我有:
class ImageInterface
{
public:
ImageInterface();
ImageInterface(const QString& path);
virtual QString getName() const = 0;
};
Run Code Online (Sandbox Code Playgroud)
并实施:
class Image : public ImageInterface
{
public:
Image();
Image(const QString& path);
QString getName() const { return name; }
private:
QString name;
};
Run Code Online (Sandbox Code Playgroud)
然后我想用它QHash:
QHash<QString, ImageInterface> *imageMap;
imageMap = new QHash<QString, ImageInterface>();
ImageInterface *im = new Image(var);
imageMap->insert(im->getName(), *im);
imageMap->take(name);
Run Code Online (Sandbox Code Playgroud)
有错误.
../EmulatorKamery/mainwindow.cpp:59:28: error: cannot allocate an object of abstract type ‘ImageInterface’
../EmulatorKamery/imageinterface.h:8:11: note: because the following virtual functions are pure …Run Code Online (Sandbox Code Playgroud)