让我们说我有2个片段,一是包含一个列表视图,另一个包含加载文本。我想,当我点击一个列表项,加载文本片段出现在列表视图的顶部。我已经调整了加载文本背景的不透明度:机器人:后台=#33FFFFFF。但它仍然只是显示了一个坚实的灰色背景加载文本。
< XML版本=1.0编码=UTF-8&GT?;
<的ListView
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:ID =@机器人:ID /列表
机器人:后台=#e8e9ee
机器人:分隔=#CCC
机器人:dividerHeight =1DP/>
片段包含一个TextView:
< XML版本=1.0编码=UTF-8&GT?;
<的TextView
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:重力=中心
机器人:文本=@字符串/ loadingText
机器人:ID =@ + ID / loadingText
机器人:文字颜色=#e8e9ee
机器人:后台=#33FFFFFF
机器人:layout_centerVertical =真
机器人:layout_centerHorizontal =真/>
我的Java code,基本上是这样的:onItemClick:
FragmentTransaction交易= manager.beginTransaction();
transaction.show(loadingFragment);
器transaction.commit();
解决方案
我做到了,它完美的作品,而不是使用.show我使用。新增但是:
活动的布局:
< RelativeLayout的
机器人:ID =@ + ID /布局
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_marginRight =5DP
机器人:layout_marginEnd =5DP>
<的FrameLayout
机器人:ID =@ + ID / list_view_container
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_centerVertical =真
机器人:layout_centerHorizontal =真正的>
< /的FrameLayout>
<的FrameLayout
机器人:ID =@ + ID / loading_text_fragment_container
机器人:layout_width =300dp
机器人:layout_height =300dp
机器人:layout_centerHorizontal =真
机器人:layout_centerVertical =真正的>
< /的FrameLayout>
< / RelativeLayout的>
在活动:
首先添加您的列表视图:
ListViewFragment listViewFragment =新ListViewFragment();
。fragmentManager.beginTransaction()加(R.id.list_view_container,listViewFragment).commit();
然后加载文本:
的 //创建一个新片段被放置在活动布局
YourFragment yourFragment =新YourFragment();
//添加片段到'item_detail_container的FrameLayout
。fragmentManager.beginTransaction()加(R.id.loading_text_fragment_container,yourFragment).commit();
在YourFragment.java
@覆盖
公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,捆绑savedInstanceState){
//充气的布局该片段
返回inflater.inflate(R.layout.your_fragment_layout,集装箱,假);
}
而your_fragment_layout.xml有没有任何特殊属性的普通的TextView。
希望它是有用的,
问候!
Let's say I have 2 fragments, one contain a list view and another contain a loading text. I want when I click on one list item, the loading text fragment appears on top of the list view. I have adjusted the opacity of the loading text background to: android:background="#33FFFFFF" . But still it just shows the loading text on a solid grey background.
<?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"/>
Fragment that contains a 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" />
My java code is basically something like this: onItemClick:
FragmentTransaction transaction=manager.beginTransaction();
transaction.show(loadingFragment);
transaction.commit();
解决方案
I did it and it works perfectly but instead of using .show I used .add:
Activity layout:
<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>
In the Activity:
First add your List View:
ListViewFragment listViewFragment = new ListViewFragment();
fragmentManager.beginTransaction().add(R.id.list_view_container, listViewFragment).commit();
Then the loading text:
// Create a new Fragment to be placed in the activity layout
YourFragment yourFragment = new YourFragment();
// Add the fragment to the 'item_detail_container' FrameLayout
fragmentManager.beginTransaction().add(R.id.loading_text_fragment_container, yourFragment).commit();
In 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);
}
And the your_fragment_layout.xml has a common TextView without any special attribute.
Hope it to be useful,
regards!