我正在处理片段,并向其中添加有趣的东西。
我想做的是在片段中添加相对布局。 相对布局具有一定的宽度,高度和可绘制状态。
似乎什么也没显示...我没有运行时错误,但什么也没显示。
这里是片段的代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
RelativeLayout relativeLayout_461 = new RelativeLayout(getContext() );
relativeLayout_461.setBackgroundResource(R.drawable.custom_layout_saldos);
RelativeLayout.LayoutParams layout_944 = new RelativeLayout.LayoutParams(150,80);
layout_944.leftMargin = 30;
layout_944.topMargin = 70;
relativeLayout_461.setLayoutParams(layout_944);
container.addView(relativeLayout_461);
View myFragmentView = inflater.inflate(R.layout.fragment_all_accounts, container, false);
RequestQueue queue = Volley.newRequestQueue(getContext());
JsonObjectRequest jsObjRequestTPV = requestAccounts(mIdUsuario);
queue.add(jsObjRequestTPV);
return myFragmentView;
}
这里有custom_layout_saldos的代码:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragment.AllAccountsFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F1F1F1"
android:fitsSystemWindows="true"
android:orientation="vertical">
</RelativeLayout>
<!-- I would expect here the new relative layout, I test the code Im adding and works via xml -->
</FrameLayout>