为什么在方向更改时没有正确加载布局文件?

时间:2015-05-30 00:29:53

标签: android android-layout layout android-edittext

我有一个带有TextView和EditText行的活动供用户输入。 EditText嵌入在布局文件中。不幸的是,在从纵向到横向的方向更改时,视图不正确,因为布局文件未完全加载。未加载布局文件的TextView,背景颜色和工具栏。仅显示EditText提示,并且显示的背景颜色默认为白色。我在三星Galaxy S3和Genymotion模拟器上测试了同样糟糕的结果。最后,当设备或仿真器从横向模式旋转回纵向时,纵向视图布局正确加载。关于为什么会发生这种情况的任何想法?

活动java文件:

public class CardViewActivity extends AppCompatActivity {

   private ListenerEditText myListenerEditText;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cardviewinput);

myListenerEditText = (ListenerEditText) findViewById(R.id.CEditText); 

EditText java文件:

public class ListenerEditText extends EditText {    
...

布局xml文件:

...
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_weight="1"
    android:background="#FF0000"        >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#FFFFFF"
        android:text=" To Do item:  "
        android:textAppearance="?android:attr/textAppearanceMedium"/>

    <com.example.jdw.secondscreen.ListenerEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/CEditText"
        android:inputType="text|textCapSentences|textNoSuggestions"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:hint="Type a new item here"
        android:textColor="#000000"
        android:singleLine="true"
        android:imeOptions="actionNext" >

        <requestFocus />
    </com.example.jdw.secondscreen.ListenerEditText>

</LinearLayout>

0 个答案:

没有答案
相关问题