java包含旋转时更改布局的子项
我最近开始将我的应用程序从iOS移植到Android,我有点挣扎。
我想做的是在一堆键值类型对中显示一些数据。
我正在使用包含的视图保存代码,下面是我的代码:
detail\u动词。xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:orientation="vertical" >
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:orientation="vertical">
<TextView
安卓:id="@+id/englishOutlet"
安卓:layout_width="fill_parent"
安卓:layout_height="wrap_content"
安卓:textSize="40sp"
安卓:textIsSelectable="false"
安卓:gravity="center_horizontal" />
<include 安卓:id="@+id/jeOutlet" layout="@layout/detail_verb_conjugation" />
<include 安卓:id="@+id/tuOutlet" layout="@layout/detail_verb_conjugation" />
<include 安卓:id="@+id/ilOutlet" layout="@layout/detail_verb_conjugation" />
<include 安卓:id="@+id/nousOutlet" layout="@layout/detail_verb_conjugation" />
<include 安卓:id="@+id/vousOutlet" layout="@layout/detail_verb_conjugation" />
<include 安卓:id="@+id/ilsOutlet" layout="@layout/detail_verb_conjugation" />
</LinearLayout>
</ScrollView>
详细描述动词的变化。xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:layout_width="fill_parent"
安卓:layout_height="fill_parent">
<TextView
安卓:id="@+id/pp"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:textIsSelectable="true"
安卓:layout_alignParentLeft="true"
安卓:textSize="20sp"
安卓:padding="10dp" />
<TextView
安卓:id="@+id/con"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_alignParentRight="true"
安卓:textIsSelectable="true"
安卓:textSize="20sp"
安卓:padding="10dp" />
<View
安卓:background="?安卓:attr/listDivider"
安卓:layout_width="fill_parent"
安卓:layout_height="1dip"
安卓:layout_centerVertical="true"
安卓:layout_below="@id/con" />
</RelativeLayout>
详细说明。java
package co.uk.iVerbs.iverbsfrench;
import 安卓.annotation.SuppressLint;
import 安卓.app.ActionBar;
import 安卓.app.Activity;
import 安卓.os.Build;
import 安卓.os.Bundle;
import 安卓.support.v4.app.NavUtils;
import 安卓.util.Log;
import 安卓.view.MenuItem;
import 安卓.widget.RelativeLayout;
import 安卓.widget.TextView;
import 安卓.content.Intent;
public class VerbDetail extends Activity {
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detail_verb);
Intent intent = getIntent();
final DataModel verb = intent.getParcelableExtra("verb");
setTitle(verb.infinitive);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
TextView textView = (TextView) findViewById(R.id.englishOutlet);
textView.setText(verb.english);
RelativeLayout rl = (RelativeLayout) findViewById(R.id.jeOutlet);
textView = (TextView)jeOutlet.findViewById(R.id.pp);
textView.setText("Je");
textView = (TextView)jeOutlet.findViewById(R.id.con);
textView.setText(verb.je);
Log.d("asf", jeOutlet.toString());
rl = (RelativeLayout) findViewById(R.id.tuOutlet);
textView = (TextView)rl.findViewById(R.id.pp);
textView.setText("Tu");
textView = (TextView)rl.findViewById(R.id.con);
textView.setText(verb.tu);
rl = (RelativeLayout) findViewById(R.id.ilOutlet);
textView = (TextView)rl.findViewById(R.id.pp);
textView.setText("Il/Elle");
textView = (TextView)rl.findViewById(R.id.con);
textView.setText(verb.il);
rl = (RelativeLayout) findViewById(R.id.nousOutlet);
textView = (TextView)rl.findViewById(R.id.pp);
textView.setText("Nous");
textView = (TextView)rl.findViewById(R.id.con);
textView.setText(verb.nous);
rl = (RelativeLayout) findViewById(R.id.vousOutlet);
textView = (TextView)rl.findViewById(R.id.pp);
textView.setText("Vous");
textView = (TextView)rl.findViewById(R.id.con);
textView.setText(verb.vous);
rl = (RelativeLayout) findViewById(R.id.ilsOutlet);
textView = (TextView)rl.findViewById(R.id.pp);
textView.setText("Ils/Elles");
textView = (TextView)rl.findViewById(R.id.con);
textView.setText(verb.ils);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case 安卓.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}
每当我旋转局部视图时,由于某种原因,所有行都会更改为“Ils/Elles”,并且该字段的相应值也会更改。这是最后一排,有人能帮忙吗?
# 1 楼答案
我遇到的问题与你的症状相同,经过多次实验发现,这是由于
属性。如果将其从xml中删除,旋转将开始正常工作。这应该是一些框架错误。我将为此提出一个问题