android setVisibility不工作 FrameLayout, LinearLayout [关闭]

问题描述 投票:0回答:1

问题是驱动程序信息不显示 !!!!我把setvisiblity(view.visible)和setvisiblity(view.invisible)任何解决方案。

我试着把方向从水平方向改为垂直方向,并做了任何改变,问题还是一样。

---> 这是我的布局:<------。

   <LinearLayout
    android:id="@+id/driverInfo"
    android:layout_width="280dp"
    android:layout_height="80dp"
    android:layout_gravity="bottom"
    android:background="@drawable/rounded_all_edge"
    android:orientation="horizontal"
    android:layout_marginBottom="70dp"
    android:layout_marginLeft="9dp"
    android:visibility="gone">

    <ImageView
        android:id="@+id/DriverProfileImage"
        android:layout_width="70sp"
        android:layout_height="70sp"
        android:src="@mipmap/ic_user_default"
        android:padding="1sp"
        android:layout_margin="5sp"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:id="@+id/DriverName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/DriverPhone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/DriverCar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/DriverCarReg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

</LinearLayout>

---> 这是我的自定义视图:<----。

     private void getDriverInfo(){

    //this is the lenarLayout 
    mDriverInfo.setVisibility(View.VISIBLE);

    DatabaseReference mClientDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child("Drivers").child(DriverFoundId);
    mClientDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            if(dataSnapshot.exists() && dataSnapshot.getChildrenCount()>0){
                Map<String,Object> map = (Map<String,Object>) dataSnapshot.getValue();
                if(map.get("name") != null){
                    mDriverName.setText("Name : "+map.get("name").toString());
                }
                if(map.get("phone") != null){
                    mDriverPhone.setText("Phone : "+map.get("phone").toString());
                }
                if(map.get("CarName") != null){
                    mDriverCar.setText("Car : "+map.get("CarName").toString());
                }
                if(map.get("CarReg") != null){
                    mDriverCarReg.setText("Matricule : "+map.get("CarReg").toString());
                }
                if(map.get("profileImageUrl") != null){
                    Glide.with(getApplication()).load(map.get("profileImageUrl").toString()).apply(RequestOptions.circleCropTransform()).into(mDriverProfileImage);
                }
            }
        }

有什么办法可以让这个LinearLayout显示出来?

android android-linearlayout visibility android-framelayout
1个回答
0
投票

代码似乎是正确的!你确定声明正确的引用 "mDriverInfo"

mDriverInfo = findViewById(R.id.driverInfo);

而你必须检查 map.get("name").toString() 是给一个字符串而不是null,因为如果它返回一个null,TextView将永远不会出现。其余的也是同样的问题,如果你写了正确的引用,试着给所有子视图添加可见性属性。我希望你能修复它

© www.soinside.com 2019 - 2024. All rights reserved.