Android:Fragment覆盖半透明的另一个片段

Gre*_*ion 10 android android-fragments

假设我有2个片段,一个包含列表视图,另一个包含加载文本.我想当我点击一个列表项时,加载文本片段出现在列表视图的顶部.我已将加载文本背景的不透明度调整为:android:background ="#33FFFFFF".但它仍然只是在坚实的灰色背景上显示加载文本.

<?xml version="1.0" encoding="utf-8"?>
<ListView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@android:id/list"
    android:background="#e8e9ee"
    android:divider="#ccc"
    android:dividerHeight="1dp"/>
Run Code Online (Sandbox Code Playgroud)

包含textview的片段:

<?xml version="1.0" encoding="utf-8"?>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="@string/loadingText"
    android:id="@+id/loadingText"
    android:textColor="#e8e9ee"
    android:background="#33FFFFFF"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />
Run Code Online (Sandbox Code Playgroud)

我的java代码基本上是这样的:onItemClick:

 FragmentTransaction transaction=manager.beginTransaction();
 transaction.show(loadingFragment);
 transaction.commit();
Run Code Online (Sandbox Code Playgroud)

Nah*_*ios 13

我做了它并且它完美地工作但不使用.show我使用.add:

活动布局:

<RelativeLayout
    android:id="@+id/layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginRight="5dp"
    android:layout_marginEnd="5dp">

    <FrameLayout
        android:id="@+id/list_view_container"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true">
    </FrameLayout>

    <FrameLayout
        android:id="@+id/loading_text_fragment_container"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true">
    </FrameLayout>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

在活动中:

首先添加列表视图:

ListViewFragment listViewFragment = new ListViewFragment();
fragmentManager.beginTransaction().add(R.id.list_view_container, listViewFragment).commit();
Run Code Online (Sandbox Code Playgroud)

然后加载文字:

// Create a new Fragment to be placed in the activity layout
YourFragment yourFragment = new YourFragment();

// Add the fragment to the 'loading_text_fragment_container' FrameLayout
fragmentManager.beginTransaction().add(R.id.loading_text_fragment_container, yourFragment).commit();
Run Code Online (Sandbox Code Playgroud)

在YourFragment.java中

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.your_fragment_layout, container, false);
}
Run Code Online (Sandbox Code Playgroud)

而且your_fragment_layout.xml有一个没有任何特殊属性的公共TextView.

希望它有用,

问候!