2016-08-02 103 views
1

下午好,我正在尝试用阴影创建ImageButton。ImageButton海拔问题

为了做到这一点:

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical" 
    android:padding="5sp"> 

    <ImageButton 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/circle_shape_little" 
     android:src="@drawable/ic_keyboard_arrow_right_black_24dp" 
     android:elevation="3sp"/> 
</LinearLayout> 

但这里是结果:

enter image description here

正如你所看到的,边界被 “腰斩”,我不知道为什么。

有人能帮助我吗?谢谢。

+0

尝试将所有'sp'改为'dp' – Enzokie

+0

没有用,谢谢! –

+0

@ D.Math尝试添加此行'android:outlineProvider =“bounds”'。 –

回答

4

layout_margin加入您的ImageButton。该elevation阴影被裁剪为View的边缘(默认为零):

<ImageButton 
    android:layout_width="match_parent" android:layout_height="match_parent" 
    android:layout_margin="5dp" 
    android:background="@drawable/circle_shape_little" 
    android:src="@drawable/ic_keyboard_arrow_right_black_24dp" 
    android:elevation="3dp"/> 

或者,你可以设置视图的padding并设置clipToPadding="false",但是这可能会导致意想不到的结果取决于你的布局。

最后,你should be使用dp除了textSize,在这种情况下,你会使用sp

+1

这是解决方案。谢谢! –