【问题标题】:Views in bottomnavigationview moving to leftside底部导航视图中的视图移动到左侧
【发布时间】:2018-08-03 05:38:12
【问题描述】:

我在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

【问题讨论】:

  • 发布包含 FrameLayout 内容的活动 xml 代码
  • 你能发布你的片段代码
  • 我添加了片段代码.. 请检查@Abhishekkumar
  • 我认为你在某处使用了约束布局,使用约束布局时发生。
  • 不,它不在任何地方使用

标签: android xml android-fragments layout


【解决方案1】:

我得到了答案.. 我在我的主要活动中使用FrameLayout 来显示片段和宽度,即 wrap_content。现在我把它改成了match_parent。现在工作正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-06
    • 1970-01-01
    • 2021-04-03
    • 2019-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多