2013-06-15 40 views
5

Tôi có một ứng dụng sử dụng các đoạn. Trên một trong các thiết bị của người dùng của tôi (HTC One), các mảnh vỡ chồng chéo nhau và màn hình của mình kết thúc lên trông như một mớ hỗn độn:Màn hình phân đoạn Android chồng lên nhau

enter image description here

Tôi đã cố gắng để tái tạo nó trên phần cứng của riêng tôi, mặc dù nó không phải HTC One. Tôi cũng đã thử sử dụng phiên bản Android 4.1.2, đó là phiên bản anh ấy có và nó hoạt động tốt. Ngắn để chạy ra ngoài để mua một HTC One, không ai có bất cứ đề nghị?

Khi tôi thêm trong đoạn mới, tôi làm bố trí này

Fragment f = new MyFragment(); 
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); 
ft.replace(R.id.mainContent, f); 
ft.addToBackStack(null); 
ft.commit(); 

My XML (tỉa lên đến các bộ phận có liên quan):

<RelativeLayout> 
    <LinearLayout> 
     <!-- My home screen content is here --> 
    </LinearLayout> 

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

CẬP NHẬT

Đoạn đó được thêm vào có bố cục này:

<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> 

Tôi đã chơi xung quanh - Tôi nhận thấy nếu tôi xóa android: nền tôi có thể tạo lại sự cố khiến tôi tin rằng HTC One đang khiến thuộc tính nền của đoạn bị bỏ qua vì một lý do nào đó.

+0

HTC One sử dụng tài nguyên xxhdpi, bạn có cung cấp cho họ không? Có vẻ như nó có thể liên quan. – Dalmas

+0

@ Dalmas, Điều đó sẽ không gây ra sự cố bố cục, điều này sẽ gây ra các vấn đề về tài nguyên, tức là tài nguyên sai đang được tải. –

Trả lời

2

Hóa ra vấn đề là một vấn đề tài nguyên, nhưng nó không rõ ràng tại sao ...

Nền tôi đã có được chỉ trong thư mục ldpi; thông thường mật độ cao hơn sẽ sử dụng bất kỳ hình ảnh nào có sẵn, tuy nhiên trong trường hợp này, thiết bị đã bỏ qua tệp đó. Một lỗi? Dunno - trong mọi trường hợp, bản sửa lỗi là tạo tài nguyên cho thư mục xxdpi trùng khớp với cùng tên.

0

Bạn có thể thử thay đổi vùng chứa phân đoạn thành FrameLayout và xem điều này vẫn xảy ra. Vì bạn có một nền tảng trên Fragment của bạn, nó nên bao gồm nền tảng trước đó. Bạn không chắc chắn tại sao điều này chỉ xảy ra trên thiết bị đó.

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

Tôi đã gặp phải tình huống tương tự và những điều sau đây đã hiệu quả đối với tôi.

Kiểm tra xem savedInstanceState nếu không-null, trong trường hợp đó, không thực hiện giao dịch phân đoạn. Nó sẽ giải quyết vấn đề này.

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(); 
} 

Hy vọng điều này sẽ hữu ích.

0

Tôi đã làm ...

bố trí MainActivity tôi

<?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> 

đoạn để chồng lên nhau bố trí là otp_fragment.xml

<?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> 

những gì tôi đã làm là

 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 
Các vấn đề liên quan