【问题标题】:Layout is just blank?布局只是空白?
【发布时间】:2018-07-29 19:25:47
【问题描述】:

我已经重新启动了 Android Studio,我已经使缓存失效,我已经同步了很多次.. 似乎没有任何工作。我的主题或 SDK 有问题吗?

它在我的预览中仍然显示为空白。我在 Android 3.2.0-beta04 上,我的 gradle 版本是 4.6。请告诉我是否需要为此问题添加更多代码或信息。

build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
defaultConfig {
    applicationId "com.example.NAME.calculatorv2"
    minSdkVersion 15
    targetSdkVersion 23
    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:23.4.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:23.4.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main"
    tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@color/lightPureBlue">

        <TextView
            android:id="@+id/result_id"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:gravity="right|center_vertical"
            android:hint="@string/base"
            android:textSize="30sp" />
    </RelativeLayout>


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="@color/pureBlue">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:layout_gravity="center"
        android:gravity="center"
        android:paddingTop="10dp">

        <Button
            android:id="@+id/four"
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="@+string/four"
            android:textSize="30sp" />

        <Button
            android:id="@+id/five"
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="@+string/five"
            android:textSize="30sp" />

        <Button
            android:id="@+id/six"
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="@+string/six"
            android:textSize="30sp" />

        <Button
            android:id="@+id/subtract"
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="@+string/subtract"
            android:textSize="30sp" />

    </LinearLayout>
</RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@color/pureBlue">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:layout_gravity="center"
            android:gravity="center"
            android:paddingTop="10dp">

            <Button
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:id="@+id/one"
                android:textSize="30sp"
                android:text="@+string/one"
                style="?android:attr/borderlessButtonStyle"/>

            <Button
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:id="@+id/two"
                android:textSize="30sp"
                android:text="@+string/two"
                style="?android:attr/borderlessButtonStyle"/>

            <Button
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:id="@+id/three"
                android:textSize="30sp"
                android:text="@+string/three"
                style="?android:attr/borderlessButtonStyle"/>

            <Button
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:id="@+id/mul"
                android:textSize="30sp"
                android:text="@+string/mul"
                style="?android:attr/borderlessButtonStyle"/>

        </LinearLayout>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@color/pureBlue">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:layout_gravity="center"
            android:gravity="center"
            android:paddingTop="10dp">

            <Button
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:id="@+id/zero"
                android:textSize="30sp"
                android:text="@+string/zero"
                style="?android:attr/borderlessButtonStyle"/>

            <Button
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:id="@+id/clear"
                android:textSize="30sp"
                android:text="@+string/clear"
                style="?android:attr/borderlessButtonStyle"/>

            <Button
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:id="@+id/equal"
                android:textSize="30sp"
                android:text="@+string/equal"
                style="?android:attr/borderlessButtonStyle"/>

            <Button
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:id="@+id/div"
                android:textSize="30sp"
                android:text="@+string/div"
                style="?android:attr/borderlessButtonStyle"/>

        </LinearLayout>



    </RelativeLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:gravity="center"
    android:orientation="horizontal"
    android:paddingTop="10dp">

    <Button
        android:id="@+id/seven"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="@+string/seven"
        android:textSize="30sp" />

    <Button
        android:id="@+id/eight"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="@+string/eight"
        android:textSize="30sp" />

    <Button
        android:id="@+id/nine"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="@+string/nine"
        android:textSize="30sp" />

    <Button
        android:id="@+id/add"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="@+string/add"
        android:textSize="30sp" />

</LinearLayout>

【问题讨论】:

  • 你的布局高度和宽度是故意的吗?
  • 如果您的布局以前可以正常工作,并且在模拟器上看起来不错,这可能是最近很多人报告的问题。 Hereherehere。似乎是最近的一个错误,听起来您已经尝试了大多数发布的解决方案......
  • @unkgd 这就是它在我的课堂视频中展示的方法
  • 正如@TylerV 提到的,它在设备本身上是否正确显示?还是两者都坏了?如果我两者兼有,请尝试将 0dp 与 wrap_contant 或 match_parent 交换。 0dp 通常用于 ConstraintLayout 以使视图匹配约束而不是固定大小
  • 你能分享你的清单和 style.xml 让我们追踪它吗?

标签: android


【解决方案1】:

我最近遇到了类似的问题。帮助我的是改变应用主题。在您的情况下,它似乎是“NoActionBar”。尝试将其更改为 MaterialLight

这是过程的动画

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-13
    • 2016-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 2018-06-02
    • 2013-01-25
    相关资源
    最近更新 更多