【发布时间】:2018-08-31 20:31:47
【问题描述】:
目前正在学习如何构建一个 android 应用程序,我的 xml 文件应该在布局预览中显示文本 Sup doge,但它根本没有显示。
现在我遇到了一个问题,我需要不断构建应用程序,以便在我应该在布局中查看它时查看模拟器中的任何小的 UI 更改。
更新 #1:
我尝试了@Khemraj 建议的 Invalidate Cache & Restart 并删除了约束属性。还删除了tools:text="@string/app_name" 部分,但它在布局预览中仍显示为空白。构建应用程序时它仍然显示良好。
更新 #2:
更新 #3
这里是 gradle 文件夹文件:
HeadFirstProject01 文件
谁能帮我解决这个问题?
解决方案:
感谢 Khenraj 的回答,我使用的是不稳定的 sdk 版本,因此我必须将其更新到以前的稳定版本,然后再次构建和同步 gradle:
android {
compileSdkVersion 27 //previously was 28
defaultConfig {
applicationId "com.example.headfirstproject_01.headfirstproject_01"
minSdkVersion 14
targetSdkVersion 27 //previously was 28
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.1.1' //previously was 28.0.0-rc02
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'
}
【问题讨论】:
-
您需要更改字符串文件夹中的
app_name字符串(我认为问题出在tools:text =@string/app_name" -
尝试在TextView上添加背景,问题是预览根本不起作用。
-
使用属性 android:layout_alignParentLeft="true" 也因为错误显示在您的 xml 文件中
标签: android xml android-layout