小编dar*_*rja的帖子

LauncherActivity用法

你能解释一下LauncherActivity的用途和用法吗?文档说它"显示可以为给定意图执行的所有活动的列表".我知道它应该自动构建应用程序中找到的所有活动的列表并提供它们的启动.我对吗?

以及如何使用它?我在网上找不到任何例子.

android android-activity

5
推荐指数
1
解决办法
1906
查看次数

处理在Android中旋转的活动

我需要为我的活动的纵向和横向方向应用不同的布局.此外,如果方向是肖像,我需要显示警报.

android:configChanges="orientation|keyboardHidden"在AndroidManifest中指定了.我也像这样重写onConfigurationChanged方法:

@Override
public void onConfigurationChanged(Configuration newConfig)
{
    Log.d("tag", "config changed");
    super.onConfigurationChanged(newConfig);

    int orientation = newConfig.orientation;
    if (orientation == Configuration.ORIENTATION_PORTRAIT)
        Log.d("tag", "Portrait");
    else if (orientation == Configuration.ORIENTATION_LANDSCAPE)
        Log.d("tag", "Landscape");
    else
        Log.w("tag", "other: " + orientation);

    ....
}
Run Code Online (Sandbox Code Playgroud)

从横向旋转到纵向日志时看起来像:

config changed
Portrait
Run Code Online (Sandbox Code Playgroud)

但是,当从纵向变为风景时,它看起来像

config changed
Portrait
config changed
Landscape
Run Code Online (Sandbox Code Playgroud)

为什么onConfigurationChanged被调用两次?我怎么能避免呢?

android orientation onconfigurationchanged android-activity

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

不应调用WebView.addJavascriptInterface

AndroidStudio开始向我显示警告"不应该调用WebView.addJavascriptInterface".但是这种方法存在并且不被弃用.它出什么问题了?可能是我遗漏了一些东西,现在有更好的方式与Javascript进行交互?

android android-webview android-studio

4
推荐指数
1
解决办法
1325
查看次数

Android Studio 1.2 Beta 3中的Traceview在哪里?

Android Studio与Traceview(http://tools.android.com/tips/traceview)很好地集成在一起.但我最近更新到1.2 Beta 3,但找不到此按钮.你能帮我吗?

android ddms android-traceview android-studio

3
推荐指数
1
解决办法
1319
查看次数

将TextView与RelativeLayout对齐

我有这样的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:background="@drawable/bgr">
    <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true"
            >
        <TextView android:layout_width="60dp" android:layout_height="wrap_content"
                  android:id="@+id/label"
                  style="@style/ConnectionPoint.Label"
                  android:text="Title"
                />
        <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
                  android:id="@+id/code"
                  style="@style/ConnectionPoint.Code"
                  android:text="CODE"
                />
        <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
                  android:id="@+id/name"
                  android:layout_toRightOf="@id/label"
                  android:layout_toLeftOf="@id/code"
                  style="@style/ConnectionPoint.Name"
                  android:text="Some text"
                />
    </RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

和风格:

<style name="ConnectionPoint.Text" parent="android:TextAppearance">
    <item name="android:layout_alignParentBottom">true</item>
</style>
<style name="ConnectionPoint.Label" parent="ConnectionPoint.Text">
    <item name="android:textColor">@color/from_to</item>
    <item name="android:layout_marginLeft">5dp</item>
    <item name="android:layout_marginRight">10dp</item>
    <item name="android:textSize">16dp</item>
</style>
<style name="ConnectionPoint.Name" parent="ConnectionPoint.Text">
    <item name="android:textSize">26dp</item>
    <item name="android:textStyle">bold</item>
    <item name="android:singleLine">true</item>
    <item name="android:ellipsize">end</item>
</style>
<style name="ConnectionPoint.Code" parent="ConnectionPoint.Text">
    <item name="android:textColor">@color/iata</item>
    <item name="android:textSize">18dp</item>
    <item name="android:singleLine">true</item>
    <item name="android:layout_alignParentRight">true</item>
    <item …
Run Code Online (Sandbox Code Playgroud)

android center textview relativelayout

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

Android在hdpi设备上缩放hdpi图像

我注意到我的应用程序中的所有图像似乎都比原件小.例如.

我把图像放在这样的活动上:

<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content"
           android:src="@drawable/ic_search_dark"
           />
Run Code Online (Sandbox Code Playgroud)

我从结果中截取屏幕截图并将图像测量为25x25:

http://petromi.com/get/86b23cdb63.png

但它的实际尺寸是28x28:

http://petromi.com/get/fd68913104.png

图像已放置到drawables-hdpi文件夹中.设备是1280x800平板电脑.我已将其显示指标记录如下:

Log.d("Screen (%s, %s) - [%s, %s] [%s]", dm.widthPixels, dm.heightPixels, dm.xdpi, dm.ydpi, dm.densityDpi);
Run Code Online (Sandbox Code Playgroud)

我得到了:

Screen (1280, 736) - [160.0, 160.15764] [213]
Screen (800, 1216) - [160.0, 160.15764] [213]
Run Code Online (Sandbox Code Playgroud)

(用于肖像和风景)

我很惊讶Android在hdpi设备上从drawable-hdpi缩放图像.可以吗?如果是的话,你能给我一个描述这些规则的链接吗?

android hdpi android-resources

1
推荐指数
1
解决办法
240
查看次数

pathPattern,其中包含intent-filter中的参数

我希望我的应用程序继续进行一些Web链接.我在清单中为此添加了intent-filter.它看起来像这样:

<activity android:name=".SomeActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http" android:host="*.something.com" />
        <data android:pathPattern="/.*/download/.*" />
    </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)

有用.但后来我被要求只处理那些指定精确参数的网址.所以,我改变了pathPattern这样:

<data android:pathPattern="/.*/download/.*param=.*" />
Run Code Online (Sandbox Code Playgroud)

然后我尝试在浏览器URL中打开http://something.com/en/download/what?param=1234 但是模式不起作用,我的应用程序不提供打开.

我对参数有疑问.可能pathPattern根本不看他们?或者我还做错了什么?

android intentfilter android-manifest android-intent

1
推荐指数
1
解决办法
1243
查看次数