第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Android LinearLayout,設置背景為透明

Android LinearLayout,設置背景為透明

Smart貓小萌 2023-04-13 15:28:54
我正在給一個bottom_sheet_layout. 它包含一個 LinearLayout 作為根元素。它有一個子 CardView。我試過以下方法:setting `android:background` property to     1. #00FFFFFF    2. #00000000    3. @android:color/transparentsetting the background color of LinearLayout programatically    `LinearLayout l = container.findViewById(R.id.root_element);     l.setBackgroundColor(Color.TRANSPARENT);`這是BottomSheet.Class鏈接到bottom_sheet_layout@Overridepublic View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {View v = inflater.inflate(R.layout.bottom_sheet_layout, container, false);LinearLayout l = container.findViewById(R.id.root_element);l.setBackgroundColor(Color.TRANSPARENT);return v;}這是Map Fragment。這是我充氣的地方bottom_sheet_layout<?xml version="1.0" encoding="utf-8"?><fragment xmlns:android="http://schemas.android.com/apk/res/android"xmlns:map="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/map"android:name="com.google.android.gms.maps.SupportMapFragment"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MapsActivity" />按照幾個指南,我仍然無法使該#00FFFFFF方法起作用。以編程方式將顏色設置為透明會使應用程序崩潰。似乎在 StackOverflow 的早期問題中,將背景設置為具有 alpha 值的十六進制代碼用于工作。現(xiàn)在我只有一個暗灰色的背景。應用截圖圖像布局應用截圖
查看完整描述

3 回答

?
月關寶盒

TA貢獻1772條經(jīng)驗 獲得超5個贊

如果您不使用MapView,我認為您是bottom_sheet_layout在同一片段中對 Google Map + 進行充氣。如果是,我認為您的問題不是 LinearLayout 透明度,而是您插入bottom_sheet_layout到片段容器的底部,而不是地圖上方。


您可以將此布局用于您的地圖片段(androidx,但如果您使用的是 android,則非常相似)


<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout 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:orientation="vertical"

    android:layout_width="match_parent"

    android:layout_height="match_parent">


    <!-- use this fragment for your google map -->

    <fragment

        android:id="@+id/google_map"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        />



    <!-- use this fragment for your bottom_sheet class -->    

    <fragment

        android:id="@+id/bottom_sheet"

        android:layout_margin="16dp"            // with this you do not need the LinearLayout root_element 

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        app:layout_constraintBottom_toBottomOf="parent"/>


</androidx.constraintlayout.widget.ConstraintLayout>

然后,您可以使用您的CardView( 或LinearLayout)visibility來顯示或不顯示該卡。


其他布局也是可能的,比如直接使用卡片視圖而不是Fragment.


查看完整回答
反對 回復 2023-04-13
?
桃花長相依

TA貢獻1860條經(jīng)驗 獲得超8個贊

我想我可以為您提供某種解決方案,您也可以嘗試看看是否可行。


在 .java文件中使用alpha 屬性

根據(jù)您的輕松程度調(diào)整值


LinearLayout l = container.findViewById(R.id.root_element);

l.setAlpha(0.4);

您也可以在 XML 文件中使用 alpha:

<LinearLayout

  android:id="@+id/l1"

  android:alpha="0.5"

  android:layout_width="190dp"

  android:layout_height="match_parent">

0.0 表示完全透明,1.0 表示完全不透明。


讓我知道是否有任何解決方案適合您。然而,在這里做更多的研究,你一定會得到一個解決方案??鞓返木幋a。


查看完整回答
反對 回復 2023-04-13
?
慕婉清6462132

TA貢獻1804條經(jīng)驗 獲得超2個贊

嘗試背景為空。


<LinearLayout

          android:orientation="vertical"

          android:layout_width="wrap_content"

          android:layout_height="match_parent"

          android:background="@null">


        ......


      </LinearLayout>


查看完整回答
反對 回復 2023-04-13
  • 3 回答
  • 0 關注
  • 869 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號