进度条未显示在片段[ANDROID]中

时间:2017-04-27 04:56:58

标签: android android-webview android-progressbar

在我的应用程序中,我正在使用此库 https://github.com/DmitryMalkovich/circular-with-floating-action-button 用浮动操作按钮实现进度条。它的工作活动,但当我在我的片段的布局进度条中包含此布局时,不会显示。 这是我的代码,以便更好地解释 请指导我哪里出错了 任何帮助将不胜感激。 的 customlayout.xml

<div class="orig-post" (mousemove)="onMouseMove($event.target.value)"></div>

onMouseMove(event: MouseEvent): void {
    this.target = event.target
    console.log(this.target) // Outputs the element the mouse is currently over
}

fragmentlayout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="gone"
   >

<com.dmitrymalkovich.android.ProgressFloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:clickable="true">

        <ProgressBar
            android:id="@+id/progressbar"
            style="@style/Widget.AppCompat.ProgressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"/>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/floatingActionButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/transparent_logo"
            app:backgroundTint="@color/bg_color"
            android:layout_centerInParent="true"
           />

   </com.dmitrymalkovich.android.ProgressFloatingActionButton>


</RelativeLayout>

我正在隐藏并在运行时显示customlayout.xml的父布局,当我从服务中获取数据时,在服务调用之前我用 View.VISIBLE 显示它并且在服务调用后我用它隐藏它强> View.GONE

已更新 Java代码

片段

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layoutcontainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="bg_color"
    >
    <include
        layout="@layout/customlayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
   <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <include
        layout="@layout/otherlayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>

CustomClass

public class MyFragment extends Fragment {
    private Context context;

    //root view of layout
    View rootView;
    private static final String ARG_PARAM1 = "Class";
    private String screen_title;
    private String URL = "";

    public MyFragment() {
        // Required empty public constructor
    }

    public static MyFragment newInstance(String param1) {
        MyFragmentfragment = new MyFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = getActivity();
        if (getArguments() != null) {
            screen_title = getArguments().getString(ARG_PARAM1);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        rootView = inflater.inflate(R.layout.fragmentlayout, container, false);
        //find views by ids
        getData();
        return rootView;
    }

    private void getData() {
        CustomClass.getInstance(context, rootView).show();
        //service call
       //on getting response from serivce (have implemented a listener here)
        CustomClass.getInstance(context, rootView).hide();    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }

3 个答案:

答案 0 :(得分:0)

使用父布局在底部创建customlayout。 所以你的那个布局的z索引位于顶部,它将是可见的,并且可以被你看到。

答案 1 :(得分:0)

您需要将CoordinatorLayout与FAB一起使用。

只需将您的FAB放入CoordinatorLayout

正如您所见,库示例代码建议也使用它。

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.dmitrymalkovich.android.progressfabsample.ScrollingActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/app_bar_height"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<com.dmitrymalkovich.android.ProgressFloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    android:clickable="true"
    app:layout_anchor="@id/app_bar"
    app:layout_anchorGravity="bottom|end">

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_backup_black_24dp"
        app:backgroundTint="@color/colorFab" />

    <ProgressBar
        style="@style/Widget.AppCompat.ProgressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</com.dmitrymalkovich.android.ProgressFloatingActionButton>

<com.dmitrymalkovich.android.ProgressFloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:clickable="true">

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_backup_black_24dp"
        app:backgroundTint="@color/colorFab" />

    <ProgressBar
        style="@style/Widget.AppCompat.ProgressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</com.dmitrymalkovich.android.ProgressFloatingActionButton>

答案 2 :(得分:0)

试试这个:

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
             Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            rootView = inflater.inflate(R.layout.fragmentlayout, container, false);
            //find views by ids
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    getData();
                }
            });
            return rootView;
  }

private void getData() {
     getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    CustomClass.getInstance(context, rootView).show();

        CustomClass.getInstance(context, rootView).hide(); 
                }
            });

 }