【发布时间】:2016-10-13 14:08:47
【问题描述】:
我是 Android 的初学者。目前,正在做一个自我项目。构建了一个用户个人资料页面,该页面在 Nexus 5 模拟器上呈现良好,但在 Nexus 4 模拟器上却没有。
这是两个模拟器的屏幕截图。
来自 Nexus5 模拟器
来自 Nexus4 模拟器
Nexus4 Emulator 的区别是……
- 您可以在 Nexus5 模拟器中看到带有后退按钮的顶部标题栏丢失。
- 个人资料图片变回红色背景。
这里是源代码...
activity_user_profile.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.bhramaan.android.bhramaan.UserProfileActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/activity_user_profile" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include
android:id="@+id/toolbar"
layout="@layout/tool_bar" />
<ImageView
android:id="@+id/header_cover_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="@mipmap/profile_header_background" />
<ImageButton
android:id="@+id/user_profile_photo"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_below="@+id/header_cover_image"
android:layout_centerHorizontal="true"
android:layout_marginTop="-60dp"
android:background="@drawable/profile_circular_border_imageview"
android:elevation="5dp"
android:padding="20dp"
android:scaleType="centerCrop"
android:src="@drawable/default_profile_new" />
<RelativeLayout
android:id="@+id/profile_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/header_cover_image"
android:background="#ebca0707"
android:elevation="4dp"
android:paddingBottom="24dp">
<TextView
android:id="@+id/user_profile_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="76dp"
android:text="Suresh Kumar Majhi"
android:textColor="#fff"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/user_profile_short_bio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/user_profile_name"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:text="Write codes and explore the world"
android:textColor="#fff"
android:textSize="14sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/profile_layout"
android:layout_marginTop="5dp"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#fff"
android:clickable="true"
android:elevation="4dp"
android:padding="20dp"
android:text="Android Profile UI Design" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:background="#fff"
android:clickable="true"
android:elevation="4dp"
android:padding="20dp"
android:text="Android Profile XMl UI Design" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#fff"
android:clickable="true"
android:elevation="4dp"
android:padding="20dp"
android:text="Android Profile UI Design" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:background="#fff"
android:clickable="true"
android:elevation="4dp"
android:padding="20dp"
android:text="Android Profile XMl UI Design" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#fff"
android:clickable="true"
android:elevation="4dp"
android:padding="20dp"
android:text="Android Profile UI Design" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
UserProfileActivity.java
package com.bhramaan.android.bhramaan;
import android.app.ActionBar;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class UserProfileActivity extends AppCompatActivity {
Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_profile);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
}
profile_circular_border_imageview.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="100dp" />
<solid android:color="#41ba7a" />
<stroke
android:width="3dip"
android:color="#f9f9f9" />
<padding
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp" />
</shape>
我的 Gradle 依赖项
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.bhramaan.android.bhramaan"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.roughike:bottom-bar:2.0.2'
}
任何人,请帮助我了解我做错了什么。
【问题讨论】:
-
可以添加 build.gradle 的依赖吗?
-
@mohammadrezakhalifeh 感谢您的快速回复。我现在用 Gradle 依赖项更新了我的帖子。
-
尝试重建您的项目...在回答人们提到材料设计的向后兼容性时,起初我猜想相同,但您添加了 appcompat-v7,它可能不是问题
-
在遵循@knossos 重新排序配置文件图像 XML 元素的建议后解决了该问题。现在,我需要修复工具栏的东西。我想我可以解决这个问题。
-
通过重新排序海拔问题解决了吗?
标签: android android-layout android-studio android-designer