在bottomnavigationview中移动到leftside的视图

时间:2018-02-23 07:34:56

标签: android xml android-fragments layout

我在MainActivity中有底部导航。我在底部导航中有5个选项卡。 每个片段视图都向左侧移动。我的布局宽度也匹配,父。

目前,我正在使用LinearLayout,所以它看起来像这样: Image here

当我使用FrameLayout时,它完全移动到左侧,看起来像一个列。

Profile.xml -LinearLayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_profile"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginBottom="?attr/actionBarSize"
tools:context="com.smiles.elearning.Profile">
</LinearLayout>

Dashboard.xml -FrameLayout

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_dashboard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="?attr/actionBarSize"
android:background="@color/blue_500"
android:scrollbarThumbVertical="@color/white"
tools:context="com.smiles.elearning.Dashboard">

信息中心片段

 @Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
   // return inflater.inflate(R.layout.fragment_dashboard, container, false);

    View v = inflater.inflate(R.layout.fragment_dashboard, container, false);

    listSubject = v.findViewById(R.id.listSubjects);
    subjectModelList = new ArrayList<>();

    StringRequest stringRequest = new StringRequest(Request.Method.GET, SUBJECT_URL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            try {
                JSONObject jsonObject = new JSONObject(response);
                JSONArray jsonArray = jsonObject.getJSONArray("result");

                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject j = jsonArray.getJSONObject(i);

                    SubjectModel subjectModel = new SubjectModel();

                    String subject = j.optString("subject");

                    subjectModel.setSubject(subject);

                    subjectModelList.add(subjectModel);
                }
                DashBoardListAdapter adapter = new DashBoardListAdapter(subjectModelList, getContext());
                listSubject.setAdapter(adapter);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });
    stringRequest.setShouldCache(false);
    RequestQueue queue = Volley.newRequestQueue(getContext());
    queue.add(stringRequest);

    listSubject.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

            if (i==0) {
                startActivity(new Intent(getContext(), Topics.class));
            }
        }
    });

    return v;


}

看起来像this

1 个答案:

答案 0 :(得分:0)

我得到了答案..我在我的Main活动中使用FrameLayout来显示片段和宽度,即wrap_content。现在我将其更改为match_parent。现在工作正常。