簡體   English   中英

Android資料設計 - LinearLayout提升

[英]Android material design - LinearLayout elevation

我只是從材料設計開始,並且除了使用CardView之外,還有一個問題需要升級才能使用。 具體來說,它應該在LinearLayout上工作嗎?

<LinearLayout
            android:paddingTop="10dp"
            android:orientation="vertical"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:elevation="2dp">
            <LinearLayout
                android:id="@+id/shareLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp">

                <ImageView
                    android:id="@+id/shareIcon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_share_black_48dp"/>
                <TextView
                    android:id="@+id/shareText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:paddingLeft="10dp"
                    android:text="@string/action_share"/>
            </LinearLayout>
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_computer_black_48dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:paddingLeft="10dp"
                    android:text="@string/action_desktop"/>
            </LinearLayout>

        </LinearLayout>

此代碼不會產生可見的布局高程 - 沒有陰影。 如果我把它放在CardView中,高程可以正常工作,但是我在點擊事件時遇到了問題。 我試過刪除圖像,但這沒有效果。 我只需要在CardView中包裝我想要提升的所有內容,還是有其他方法? 謝謝。

我正在測試運行Android 5.0.2的Nexus 7。

UPDATE

我按照建議嘗試了大綱提供程序,這會產生陰影,但卻是一個奇怪的陰影。

截圖

看起來LinearLayout是有角度的,而不僅僅是提升。 改變保證金似乎沒有幫助。 有人還有其他想法嗎?

使用ViewOutlineProvider為所有視圖生成陰影。 如果設置了背景,則會從視圖的背景中自動生成此類提供程序。 陰影采用背景的形狀和透明度。 要使透明視圖投射陰影,您必須設置自己的ViewOutlineProvider:

view.setOutlineProvider(new ViewOutlineProvider() {
    @Override
    public void getOutline(View view, Outline outline) {
        outline.setRect(0, 0, view.getWidth(), view.getHeight());
    }
});

確保陰影施法者有足夠的空間來繪制陰影。 默認情況下,CardView會為此添加自己的填充。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM