当我尝试将RelativeLayout
隐藏在Fragment
中时,我得到Exception
抛出空点RelativeLayout.setVisibility
的{{1}}。
这是我的Exception
代码:
Fragment
和
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.product_description_zoom_image,container,false);
layout = view.findViewById(R.id.layout_fix);
layout.setVisibility(View.GONE);
return view;
}
答案 0 :(得分:0)
似乎Android Studio无法处理太多嵌套布局。因此,请删除父级RelativeLayout,并创建一个新的Relative作为父级布局的子级,然后将所有内容放入新的Relative布局中。解决了。
或
public static String upload(File file) throws IOException {
Cloudinary cloudinary = new Cloudinary(CONFIG);
Map<Object, Object> parameters = new HashMap<>();
parameters.put("public_id", "Bookstore/Authors/Images/vejder");
Map result = cloudinary.uploader().upload(file, parameters);
return (String) result.get("url");
}
布局没有ID为product_description_zoom_image
以及您的评论问题
layout_fix
答案 1 :(得分:0)
尝试此代码。
public class HomeFragment extends Fragment {
RelativeLayout layout;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.home_fragment,container,false);
initView(view);
return view;
}
private void initView(View view) {
layout=view.findViewById(R.id.layout_fix);
layout.setVisibility(View.GONE);
}
}
xml代码。.
<?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:id="@+id/layout_fix">
<Button
android:layout_width="190dp"
android:layout_height="50dp"
android:text="Hellow"/>
</RelativeLayout>