BoxInsetLayout不起作用不起作用、BoxInsetLayout

由网友(人潮拥挤我好多余)分享简介:我在Android的工作室V1.2.2创建的样本机器人磨损的活动项目。我删除WatchViewStub和使用这个例子以与创建活动BoxInsetLayout。但BoxInsetLayout不上一轮设备正常工作。我测试了这个在摩托车360的Andr​​oid 5.1.1和摩托车360 5.0.1版本更新之前。而我测试的模...

我在Android的工作室V1.2.2创建的样本机器人磨损的活动项目。我删除WatchViewStub和使用这个例子以与创建活动BoxInsetLayout。但BoxInsetLayout不上一轮设备正常工作。我测试了这个在摩托车360的Andr​​oid 5.1.1和摩托车360 5.0.1版本更新之前。而我测试的模拟器。而且它不会在所有的工作。所有的时间,我看到这样的:

I created sample android wear activity project in android studio v1.2.2. I deleted WatchViewStub and used this example to create activity with BoxInsetLayout. But BoxInsetLayout doesn't work correctly on Round Device. And I tested this on moto 360 android 5.1.1 and before update on moto 360 version 5.0.1. And I tested this on emulator. And It doesn't work at all. All time I see this:

但必须是此

我的$ C $低于C:

My code below:

activity_main.xml

activity_main.xml

<android.support.wearable.view.BoxInsetLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:padding="15dp">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="5dp"
        android:background="@color/red"
        app:layout_box="all">

        <TextView
            android:gravity="center"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:text="Hello Android Wear"
            android:textColor="@color/black" />

        <ImageButton
            android:background="@drawable/selector_btn_ok"
            android:layout_gravity="bottom|start"
            android:layout_height="50dp"
            android:layout_width="50dp" />

        <ImageButton
            android:background="@drawable/selector_btn_cancel"
            android:layout_gravity="bottom|end"
            android:layout_height="50dp"
            android:layout_width="50dp" />
    </FrameLayout>
</android.support.wearable.view.BoxInsetLayout>

MainActivity.class

MainActivity.class

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

模块build.gradle

Module build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "mypackagename.boxinsetlayout"
        minSdkVersion 20
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.support:wearable:1.2.0'
    compile 'com.google.android.gms:play-services-wearable:7.5.0'
}

项目build.gradle

Project build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

为什么不工作?在哪里我错了吗?我如何使用正确BoxInsetLayout上的设备与圆形屏?

Why doesn't it work? Where did I mistake? And How can I use correctly BoxInsetLayout on devices with Round screen?

推荐答案

这个错误是在你的activity_main.xml,在那里你指定的:

The mistake is in your activity_main.xml, where you specified:

android:padding="15dp"

如果您删除这一点,那么它应该工作。 BoxInsetLayout使用在实施填充,你已经改变了它给出了不正确的输出,你观察到的。

If you remove this, then it should work. BoxInsetLayout uses padding in the implementation, and you have changed the value which gives the incorrect output you observed.

(编辑) 要注意的是BoxInsetLayout调整本身在这两个填料,并且还子视图是很重要的。因此,请确保您不会更改填充值或事情会打破。您可以尝试嵌入第二的FrameLayout,如果你想有更多的控制填充。

(edit) It is important to note that BoxInsetLayout adjusts the padding in both itself, and also the child views. So make sure you do not change the padding values or things will break. You can try embedding a second FrameLayout if you want to have more control over the padding.

阅读全文

相关推荐

最新文章