Android TextView在首选项屏幕中重叠(而不是覆盖)
我试图建立一个首选屏幕,其中包括一些文本视图和编辑文本首选布局 当我在活动中使用textView.setText(inputString)时,它不会覆盖现有的textView,而是创建一个新的textView副本,其中inputString为文本,并且与现有的textView重叠。setText是否有任何方式覆盖现有的TextView本身 这是带有TextView的XML布局Android TextView在首选项屏幕中重叠(而不是覆盖),android,android-layout,android-preferences,preferencescreen,Android,Android Layout,Android Preferences,Preferencescreen,我试图建立一个首选屏幕,其中包括一些文本视图和编辑文本首选布局 当我在活动中使用textView.setText(inputString)时,它不会覆盖现有的textView,而是创建一个新的textView副本,其中inputString为文本,并且与现有的textView重叠。setText是否有任何方式覆盖现有的TextView本身 这是带有TextView的XML布局 <?xml version="1.0" encoding="utf-8"?> <RelativeLay
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:background="@color/blue"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/list"
></ListView>
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:textColor="@color/pseudoBlack"
android:layout_height="wrap_content"
android:layout_marginStart="59dp"
android:layout_marginTop="100dp"
android:id="@+id/textView2"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<TextView
android:text="TextView"
android:textColor="@color/pseudoBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView5"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_toEndOf="@+id/textView2"
android:layout_marginStart="100dp" />
<TextView
android:text="TextView"
android:textColor="@color/pseudoBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="43dp"
android:id="@+id/textView11"
android:layout_below="@+id/textView2"
android:layout_toEndOf="@+id/textView2"
android:layout_marginStart="21dp" />
</RelativeLayout>
我已经添加了结果的屏幕截图
如何解决此问题?请提前感谢替换
setContentView(R.layout.inner)代码>与资源中的添加首选项(//您的首选项屏幕)代码>替换设置内容视图(R.layout.inner)代码>与资源中的添加首选项(//您的首选项屏幕)代码>我遇到过类似的问题,它发生在其他视图中,就像FrameLayout中的TextureView一样。我将我的TextureView调整得更小了,我仍然可以看到后面的上一个TextureView在闪烁
使它工作的原因很有趣->我只是在我的布局(LinearLayout)中添加了黑色背景色(可能是任何颜色),现在它工作正常
我添加了:android:background=“#000000”
如果背景不知道用什么颜色来清除它,它似乎没有被清除。我遇到过类似的问题,在其他视图中也会出现这种情况,就像FrameLayout中的TextureView一样。我将我的TextureView调整得更小了,我仍然可以看到后面的上一个TextureView在闪烁
使它工作的原因很有趣->我只是在我的布局(LinearLayout)中添加了黑色背景色(可能是任何颜色),现在它工作正常
我添加了:android:background=“#000000”
如果它不知道用什么颜色来清除背景,背景似乎没有被清除。它不起作用。如果我替换setContentView,应用程序将停止工作。它不工作。如果我更换setContentView,应用程序将停止工作。
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
>
<Preference android:layout="@layout/inner" android:key="innerkey"
/>
<Preference android:key="mskey"
android:title="show"
/>
<EditTextPreference android:key="editpref"
android:title="Add"
/>
</PreferenceScreen>
package com.example.asus.layoutcheck;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.widget.TextView;
public class SecondaryActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.inner);
TextView txt1 = (TextView)findViewById(R.id.textView2);
TextView txt2 = (TextView)findViewById(R.id.textView5);
TextView txt3 = (TextView)findViewById(R.id.textView11);
txt1.setText("First Text");
txt2.setText("Second Text");
txt3.setText("Third Text");
final String message = "This is the message" ;
addPreferencesFromResource(R.xml.pref);
final Preference msg = findPreference("mskey");
msg.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
msg.setSummary(message);
return true;
}
});
Preference edit = findPreference("editpref");
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical"
android:visibility="visible"
tools:context=".CameraActivity">