我的活动和其中的一个ImageButton有问题。它看起来像是在裁剪:
这是对应活动的XML:
<?xml version="1.0" encoding="utf-8"?>
<!-- A RecyclerView with some commonly used attributes -->
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:id="@+id/todo_linear_layout"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal">
<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:adjustViewBounds="true"
app:srcCompat="@android:drawable/ic_input_add" />
<EditText
android:id="@+id/edittodo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20px"
android:layout_weight="5"
android:textColor="@android:color/black" />
</LinearLayout>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/todo_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >
</android.support.v7.widget.RecyclerView>
</LinearLayout>
此外,Android Studio中的布局设计器可以正确显示布局:
这里的问题在哪里?我已经尝试更改边距或填充数值,但我的android设备上正在运行的应用程序中的Button仍在剪切。
发布于 2018-09-26 04:19:37
我相信发生的事情是你运行你的应用程序的设备没有@android:drawable/ic_input_add
可绘制。
我试着运行你发布的代码,一切都为我工作。但是,如果我从<ImageButton>
标记中删除app:srcCompat
属性,则会得到与您在第一个屏幕截图中发布的行为相同的行为。
一般来说,你不能100%依赖于拥有@android:
资源的设备。一些制造商删除了资源,而另一些制造商则将这些值替换为无意义的值(例如,我看到@android:color/white
看起来是灰色的)。
我建议创建您自己的可绘制(甚至可以手动从Android复制一个并将其添加到您的项目中),并引用它。
app:srcCompat="@drawable/your_own_add"
发布于 2018-09-26 16:46:11
将app:srcCompat更改为:android:src="@android:drawable/ic_input_add"
做到了!所以问题是,设备没有找到那个图标,只显示了一些灰色的东西。
https://stackoverflow.com/questions/52505950
复制相似问题