Android Studio 3.1.3, design view is always empty

后端 未结 7 1186
刺人心
刺人心 2021-02-02 10:56

I\'m new to android development and I have this problem with my Android Studio 3.1.3 demo project or any project that I create.

Even though that I can drag and drop diff

相关标签:
7条回答
  • 2021-02-02 10:57

    For those that nothing works in this page or in the whole internet(just like me), try to uninstall your android studio then reinstall. (You don't have to uninstall sdks, avd. Settings can also stay the same. Just the main program needs uninstall) When you reinstall Android Studio, change the version to 27 as in the image. That is it, hope it works for you too

    0 讨论(0)
  • 2021-02-02 11:00

    Your layout has problem with the CheckBox widget. It has no constraint. tools:layout_editor_absoluteX and tools:layout_editor_absoluteY are only affect on design mode, but not in real running app.

    Note: Don't drag/drop the widget on design view, it will generate many weird properties that not gonna work in all case, like the two properties you got. Do it in the code instead. If you want the CheckBox to be in center, do like this:

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CheckBox"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent" />
    

    This will remove the error icon at the CheckBox, then a refresh may help.

    0 讨论(0)
  • 2021-02-02 11:01

    I have been having the same problem and found that this hack worked for me. I have changed the versions in app file located in the Gradle Scripts/ build.gradle(Module:app) to versions 27. CompileSdkVersion, minSdkVersion, targetSdkVersion and implementation 'com.android.support:appcompat-v7:27.0.0'. These are listed on line 4,7,8 and 23.. (it might be different for you).

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 27
        defaultConfig {
            applicationId "com.fiv4.masterapp"
            minSdkVersion 27
            targetSdkVersion 27
            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:27.0.0'
        implementation 'com.android.support.constraint:constraint-layout:1.1.2'
        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'
    }
    

    0 讨论(0)
  • 2021-02-02 11:01

    Go to res/values/styles.xml file...

    on line 4, its always...

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    

    Change this with

    <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
    

    No need to save the file, it will automatically be saved. Go to activity_main.xml --> Design (View) ...it should be showing it now.

    0 讨论(0)
  • 2021-02-02 11:04

    Use stable version of support libraries.

    The problem is when you are using unstable alpha support libraries. See stable libraries versions on google maven repo.

    At the time of answer, most stable version of support:appcomact-v7 is 28.0.0-rc02

    Replace

    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3' // less stable alpha
    

    With

    implementation 'com.android.support:appcompat-v7:28.0.0-rc02' // more stable
    

    Sync, Just Restart AS. Problem resolved !

    • Track support:appcomact-v7 stable versions
    • Track support:design stable versions
    • Track support:recyclerview-v7 stable versions
    • Track support:cardview-v7 stable versions
    0 讨论(0)
  • 2021-02-02 11:08

    Ok my problem is solved!

    The following classes could not be instantiated: - android.support.v7.widget.Toolbar

    I changed the res/values/styles.xml file from this:

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    

    to this:

    <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
    

    and that solved the problem

    0 讨论(0)
提交回复
热议问题