【发布时间】:2017-09-24 17:27:33
【问题描述】:
在我的应用程序中,我正在使用这个库 https://github.com/DmitryMalkovich/circular-with-floating-action-button 使用浮动操作按钮实现进度条。它正在处理活动,但是当我将此布局包含在我的片段的布局进度条中时没有显示。 这是我的代码以获得更好的解释 请指导我哪里出错了 任何帮助将不胜感激。 customlayout.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>
fragmentlayout.xml
<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>
当我从服务获取数据时,我在运行时隐藏并显示 customlayout.xml 的父布局,在服务调用之前我用 View.VISIBLE 显示它,在服务调用之后我用 View.GONE
更新 Java 代码
片段
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();
}
自定义类
public class CustomClass {
private ProgressBar mProgressBar;
private FloatingActionButton mFab;
private RelativeLayout parentLayout;
private LayoutInflater inflater;
private static CustomClass custom;
private CustomClass (Context context) {
findViewsById(context);
}
private CustomClass (View view) {
findViewsById(view);
}
public static CustomClass getInstance(Context context, View view) {
custom = new CustomClass (view);
custom.setPColor(context);
return custom;
}
public static CustomClass getInstance(Context context) {
custom = new CustomClass (context);
custom.setPColor(context);
return custom;
}
private void setPColor(Context context) {
if (mProgressBar != null)
mProgressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(context, R.color.bluecolor), android.graphics.PorterDuff.Mode.MULTIPLY);
}
private void findViewsById(View view) {
if (view != null) {
mProgressBar = (ProgressBar) view.findViewById(R.id.custom_progressbar);
mFab = (FloatingActionButton) view.findViewById(R.id.custom_floatingActionButton);
parentLayout = (RelativeLayout) view.findViewById(R.id.rl_progress_fab_container);
}
}
private void findViewsById(Context context) {
Activity activity = (Activity) context;
if (activity != null) {
mProgressBar = (ProgressBar) activity.findViewById(R.id.custom_progressbar);
mFab = (FloatingActionButton) activity.findViewById(R.id.custom_floatingActionButton);
parentLayout = (RelativeLayout) activity.findViewById(R.id.rl_progress_fab_container);
}
}
public void show() {
if (custom.parentLayout != null)
custom.parentLayout.setVisibility(View.VISIBLE);
}
public void hide() {
if (custom.parentLayout != null)
custom.parentLayout.setVisibility(View.GONE);
}
【问题讨论】:
-
还要添加服务代码,你在哪里隐藏或可见进度条。
-
改变FAB和进度条的顺序
-
把你的java代码放在这里
-
@AldrinMathew 试过了,不行
-
@User 代替容器 hide ,尝试
includeid 作为隐藏和显示。
标签: android android-webview android-progressbar