我有一个奇怪的问题,我不知道它从哪里来。
我正在制作食谱应用程序,并且正在使用SQLite显示图像,描述和收藏夹复选框。对于配方说明,我不使用SQLite,而是使用TextView。
在我的应用中,我有两个活动BreakfastActivity和Breakfast2Activity,它们的布局显示了我上面提到的内容。问题是BreakfastActivity的XML代码覆盖了BreakfastActivity2布局。
注意:来自数据库的信息不会被覆盖,但是来自xml的信息会被覆盖。
我检查了Java活动是否使用相同的布局,以及布局是否使用相同的上下文。一切似乎都很好。我不知道这可能是潜在的问题。
任何帮助将不胜感激。
这是activity_breakfast xml
。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".BreakfastActivity">
//I added shadow to the toolbar using design library
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
//I referenced other layout (tool bar layout)
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_main" />
</android.support.design.widget.AppBarLayout>
<ImageView
android:id="@+id/photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:maxWidth="600dp"
android:maxHeight="300dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
/>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:textSize="20dp"
android:textColor="#454444"
android:textStyle="bold"/>
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="10dp"/>
<TextView
android:id="@+id/instructionsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="5dp"
android:text="Instructions"
android:paddingLeft="10dp"
android:textSize="20dp" />
<TextView
android:id="@+id/instructionsStepsCrepes1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="@string/instructionsCrepesStep1"/>
<TextView
android:id="@+id/instructionsStepsCrepes2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="@string/instructionsCrepesStep1"/>
<TextView
android:id="@+id/instructionsStepsCrepes3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="@string/instructionsCrepesStep3"/>
<CheckBox
android:id="@+id/favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/favorite"
android:layout_weight="2"
android:paddingLeft="10dp"
android:onClick="onFavoriteClicked"/>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_gravity="bottom"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@color/colorPrimaryDark"
app:itemTextColor="@color/colorPrimaryDark"
app:menu="@menu/bottom_nav_menu">
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_above="@id/bottom_navigation"
android:background="@drawable/shadow"/>
</android.support.design.widget.BottomNavigationView>
</android.support.design.widget.AppBarLayout>
</LinearLayout>
</ScrollView>
这是BreakfastActivity.java
public class BreakfastActivity extends AppCompatActivity {
public static final String EXTRA_BREAKFASTID ="breakfastId";
private ShareActionProvider shareActionProvider;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_breakfast);
这是activity_breakfast2 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".Breakfast2Activity">
//I added shadow to the toolbar using design library
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
//I referenced other layout (tool bar layout)
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_main" />
</android.support.design.widget.AppBarLayout>
<ImageView
android:id="@+id/photoBreakfast2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:maxWidth="600dp"
android:maxHeight="300dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"/>
<TextView
android:id="@+id/nameBreakfast2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/descriptionBreakfast2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/instructionsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="5dp"
android:text="Instructions"
android:paddingLeft="10dp"
android:textSize="20dp" />
<TextView
android:id="@+id/instructionsStepsOmellete1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="@string/instructionsOmelleteStep1"/>
<TextView
android:id="@+id/instructionsStepsOmellete2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="@string/instructionsOmelleteStep2"/>
<TextView
android:id="@+id/instructionsStepsOmellete3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="@string/instructionsOmelleteStep3"/>
<CheckBox
android:id="@+id/favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/favorite"
android:layout_weight="2"
android:onClick="onFavoriteClicked"/>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_gravity="bottom"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@color/colorPrimaryDark"
app:itemTextColor="@color/colorPrimaryDark"
app:menu="@menu/bottom_nav_menu" >
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_above="@id/bottom_navigation"
android:background="@drawable/shadow"/>
</android.support.design.widget.BottomNavigationView>
</android.support.design.widget.AppBarLayout>
这是ActivityBreakfast2.java
public class Breakfast2Activity extends AppCompatActivity {
public static final String EXTRA_BREAKFAST2ID = "BREAKFAST2Id";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_breakfast2);