布局没有显示出来

时间:2017-12-29 09:22:14

标签: android android-cardview

我正在尝试为Fragment创建一个布局。这是我的xml布局。

Fragment_profil.xml

<FrameLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.boby.srsly.ProfilFragment">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.CardView
            android:id="@+id/card_view"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_gravity="center"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            app:cardCornerRadius="4dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.517"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.027">

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/fullnametext"
                    android:layout_width="144dp"
                    android:layout_height="18dp"
                    android:layout_marginBottom="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="64dp"
                    android:text="fullnametext"
                    app:layout_constraintBottom_toTopOf="@+id/notelptext"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.716"
                    app:layout_constraintStart_toEndOf="@+id/fullnameLabel"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias="0.26" />

                <TextView
                    android:id="@+id/fullnameLabel"
                    android:layout_width="117dp"
                    android:layout_height="23dp"
                    android:layout_marginBottom="8dp"
                    android:layout_marginStart="16dp"
                    android:layout_marginTop="76dp"
                    android:text="Fullname"
                    app:layout_constraintBottom_toTopOf="@+id/textView4"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias="0.0" />

                <TextView
                    android:id="@+id/textView4"
                    android:layout_width="117dp"
                    android:layout_height="23dp"
                    android:layout_marginBottom="24dp"
                    android:layout_marginEnd="64dp"
                    android:text="No Telp"
                    app:layout_constraintBottom_toTopOf="@+id/textView6"
                    app:layout_constraintEnd_toStartOf="@+id/notelptext" />

                <TextView
                    android:id="@+id/notelptext"
                    android:layout_width="144dp"
                    android:layout_height="20dp"
                    android:layout_marginBottom="24dp"
                    android:layout_marginEnd="28dp"
                    android:text="notelp"
                    app:layout_constraintBottom_toTopOf="@+id/deskripsitxt"
                    app:layout_constraintEnd_toEndOf="parent" />

                <TextView
                    android:id="@+id/textView6"
                    android:layout_width="117dp"
                    android:layout_height="23dp"
                    android:layout_marginEnd="60dp"
                    android:text="Deskripsi"
                    app:layout_constraintEnd_toStartOf="@+id/deskripsitxt"
                    tools:layout_editor_absoluteY="180dp" />

                <TextView
                    android:id="@+id/deskripsitxt"
                    android:layout_width="144dp"
                    android:layout_height="63dp"
                    android:layout_marginBottom="252dp"
                    android:layout_marginEnd="28dp"
                    android:text="TextView"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent" />
            </android.support.constraint.ConstraintLayout>
        </android.support.v7.widget.CardView>
    </android.support.constraint.ConstraintLayout>

</FrameLayout>

但是,当我运行它时我只看到白色背景,我的意思是因为这是bottomnavigationview我只能看到上面写的navigation。我该如何解决它,是否缺少某些东西?提前谢谢,抱歉我的英语不好。

这是我的ProfilFragment.java

public class ProfilFragment extends Fragment {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_profil, container, false);
        SharedPreferences mPrefs = this.getActivity().getSharedPreferences("userinfoafterlogin", MODE_PRIVATE); //add key
        String response = mPrefs.getString("userinfo", null);

        try{
            JSONObject json = new JSONObject(response);
            json = (JSONObject)json.get("nameValuePairs");
            json = (JSONObject)json.get("userData");
            json = (JSONObject)json.get("nameValuePairs");
            String fullname = (String)json.get("fullname");
            String phone = (String)json.get("phone");
            String desc = (String)json.get("Deskripsi");

            TextView labelfullname  = (TextView)v.findViewById(R.id.fullnametext);
            TextView labeltelp      = (TextView)v.findViewById(R.id.notelptext);
            TextView labeldesc      = (TextView)v.findViewById(R.id.deskripsitxt);

            labelfullname.setText(fullname);
            labeltelp.setText(phone);
            labeldesc.setText(desc);

            return v;
        }catch (JSONException e) {
            Log.e("MYAPP", "unexpected JSON exception", e);
            return v;
        }

    }


}

1 个答案:

答案 0 :(得分:1)

试试这个

{{1}}

<强>输出

enter image description here