Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android片段屏幕重叠_Android_Android Layout - Fatal编程技术网

Android片段屏幕重叠

Android片段屏幕重叠,android,android-layout,Android,Android Layout,我有一个使用碎片的应用程序。在我的用户的一台设备(HTC one)上,碎片相互重叠,他的屏幕看起来乱七八糟: 我尝试在自己的硬件上复制它,尽管它不是HTC的。我也尝试过使用安卓版本4.1.2,这是他拥有的版本,运行良好。除了买一台HTC之外,还有人有什么建议吗 当我添加新片段时,我会这样做 Fragment f = new MyFragment(); FragmentTransaction ft = getActivity().getSupportFragmentManager().beg

我有一个使用碎片的应用程序。在我的用户的一台设备(HTC one)上,碎片相互重叠,他的屏幕看起来乱七八糟:

我尝试在自己的硬件上复制它,尽管它不是HTC的。我也尝试过使用安卓版本4.1.2,这是他拥有的版本,运行良好。除了买一台HTC之外,还有人有什么建议吗

当我添加新片段时,我会这样做

 Fragment f = new MyFragment();
 FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
 ft.replace(R.id.mainContent, f);
 ft.addToBackStack(null);
 ft.commit();
我的XML布局(裁剪为相关部分):


更新

添加的片段具有以下布局:

<RelativeLayout 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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@drawable/app_bg"    
    tools:context=".DeviceListActivity" >

    <!-- snipped! (for brevity) -->
</RelativeLayout>


我一直在玩-我注意到,如果我删除android:background,我可以重现这个问题,这让我相信HTC One会因为某种原因导致片段的背景属性被忽略。

您可以尝试将片段容器更改为FrameLayout,看看是否仍然发生这种情况。既然你的片段上有背景,它应该会掩盖上一个。不知道为什么这只发生在那个设备上

<!-- This is where the fragment gets placed -->
<FrameLayout android:id="@+id/mainContent"
             android:layout_width="match_parent"
             android:layout_height="match_parent">

原来问题是资源问题,但不清楚为什么


我的背景只在ldpi文件夹中;通常,较高的密度将使用任何可用的图形,但是在这种情况下,设备忽略了该文件。虫子?不知道-在任何情况下,修复方法是为匹配相同名称的xxdpi文件夹创建一个资源。

我遇到过类似的情况,以下方法对我有效

检查savedInstanceState是否为null,在这种情况下,不执行片段事务。它将解决这个问题

if (homeFragment == null) {
    if (savedStateInstance != null) {
    homeFragment = (HomeFragment) fragmentManager.findFragmentByTag(HOME_FRAGMENT);
    return;
}
// tie new fragment
homeFragment = new HomeFragment();
homeFragment.setArguments(bundle);
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.add(homeFragment, HOME_FRAGMENT);
transaction.commit();
}
希望这有帮助。

我已经做了

我的主要活动布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    android:padding="10dp">

    <RelativeLayout
        android:id="@+id/registerContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/usernameEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="15dp"
            android:layout_marginTop="15dp"
            android:hint="USERNAME"
            android:textColorHint="#FFFFFF"
            android:textColor="#FFFFFF"
            android:background="@drawable/edittext_style"
            android:textAlignment="center"/>

        <EditText
            android:id="@+id/passEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="15dp"
            android:layout_marginTop="15dp"
            android:inputType="textPassword"
            android:hint="PASSWORD"
            android:textColorHint="#FFFFFF"
            android:textColor="#FFFFFF"
            android:textAlignment="center"
            android:background="@drawable/edittext_style"
            android:layout_below="@id/usernameEditText"/>


        <EditText
            android:id="@+id/phoneEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="15dp"
            android:layout_marginTop="15dp"
            android:inputType="phone"
            android:hint="PHONE NUMBER"
            android:textColorHint="#FFFFFF"
            android:textColor="#FFFFFF"
            android:background="@drawable/edittext_style"
            android:textAlignment="center"
            android:layout_below="@id/passEditText"/>

        <EditText
            android:id="@+id/emailEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="15dp"
            android:layout_marginTop="15dp"
            android:inputType="textEmailAddress"
            android:hint="EMAIL"
            android:textColorHint="#FFFFFF"
            android:textColor="#FFFFFF"
            android:background="@drawable/edittext_style"
            android:textAlignment="center"
            android:layout_below="@id/phoneEditText"/>

        <Button
            android:id="@+id/registerEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/emailEditText"
            android:text="REGISTER"
            android:layout_marginTop="20dp"
            android:background="#0b999b"
            android:textColor="#000000"
            android:textSize="18dp"/>


    </RelativeLayout>

    <FrameLayout
        android:id="@+id/otpfragmentcontainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></FrameLayout>


</RelativeLayout>

HTC One使用xxhdpi资源,您是否提供这些资源?似乎它可能是相关的。@Dalmas,这不会导致布局问题,它会导致资源问题,即加载了错误的资源。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    android:padding="10dp">

    <RelativeLayout
        android:id="@+id/registerContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/usernameEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="15dp"
            android:layout_marginTop="15dp"
            android:hint="USERNAME"
            android:textColorHint="#FFFFFF"
            android:textColor="#FFFFFF"
            android:background="@drawable/edittext_style"
            android:textAlignment="center"/>

        <EditText
            android:id="@+id/passEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="15dp"
            android:layout_marginTop="15dp"
            android:inputType="textPassword"
            android:hint="PASSWORD"
            android:textColorHint="#FFFFFF"
            android:textColor="#FFFFFF"
            android:textAlignment="center"
            android:background="@drawable/edittext_style"
            android:layout_below="@id/usernameEditText"/>


        <EditText
            android:id="@+id/phoneEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="15dp"
            android:layout_marginTop="15dp"
            android:inputType="phone"
            android:hint="PHONE NUMBER"
            android:textColorHint="#FFFFFF"
            android:textColor="#FFFFFF"
            android:background="@drawable/edittext_style"
            android:textAlignment="center"
            android:layout_below="@id/passEditText"/>

        <EditText
            android:id="@+id/emailEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="15dp"
            android:layout_marginTop="15dp"
            android:inputType="textEmailAddress"
            android:hint="EMAIL"
            android:textColorHint="#FFFFFF"
            android:textColor="#FFFFFF"
            android:background="@drawable/edittext_style"
            android:textAlignment="center"
            android:layout_below="@id/phoneEditText"/>

        <Button
            android:id="@+id/registerEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/emailEditText"
            android:text="REGISTER"
            android:layout_marginTop="20dp"
            android:background="#0b999b"
            android:textColor="#000000"
            android:textSize="18dp"/>


    </RelativeLayout>

    <FrameLayout
        android:id="@+id/otpfragmentcontainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></FrameLayout>


</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:background="@color/colorPrimary">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/textviewOTP"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Enter Your OTP"
            android:textColor="#0b999b"
            android:textStyle="bold"
            android:textSize="24dp"
            android:textAlignment="center"
            android:layout_marginTop="200dp"
            android:layout_marginBottom="5dp"/>

        <EditText
            android:id="@+id/otpEditText"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:padding="15dp"
            android:layout_marginTop="15dp"
            android:inputType="phone"
            android:hint="EX: 456789"
            android:textColorHint="#FFFFFF"
            android:textColor="#FFFFFF"
            android:background="@drawable/edittext_style"
            android:textAlignment="center"
            android:layout_below="@id/textviewOTP"/>

        <Button
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="ENTER"
            android:background="#0b999b"
            android:layout_centerHorizontal="true"
            android:layout_below="@id/otpEditText"/>


    </RelativeLayout>

</LinearLayout>
        registerContainer.setVisibility(View.GONE);

        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        OTPFragment otpFragment = new OTPFragment();
            fragmentTransaction.add(R.id.otpfragmentcontainer, otpFragment);
            fragmentTransaction.commit();

which disable registerContainer and display my fragment layout