很好很简单:
测试代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingTop="100dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
app:srcCompat="@drawable/ic_dislike" />
<ImageButton
android:id="@+id/imageButton"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/imageView"
android:layout_marginTop="20dp"
app:srcCompat="@mipmap/ic_launcher" />
</RelativeLayout>
“真实代码”也发生了同样的事情:
<RelativeLayout
android:id="@+id/counters"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#FF0000"
android:gravity="center_vertical">
<RelativeLayout
android:id="@+id/views_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/views_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="4dp"
android:background="#FFFF"
app:srcCompat="@drawable/ic_views" />
<TextView
android:id="@+id/views_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/views_img"
android:background="@color/colorAccent"
android:text="27,547"
android:textColor="#000" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/likes_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/views_layout">
<ImageButton
android:id="@+id/likes_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:background="#FFFF"
app:srcCompat="@drawable/ic_like" />
<TextView
android:id="@+id/likes_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/likes_img"
android:text="1,232"
android:textColor="#000" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/dislikes_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/likes_layout">
<ImageButton
android:id="@+id/dislikes_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:background="#FFFF"
app:srcCompat="@drawable/ic_dislike" />
<TextView
android:id="@+id/dislikes_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/dislikes_img"
android:text="112"
android:textColor="#000" />
</RelativeLayout>
</RelativeLayout>
<!--title and desc-->
<RelativeLayout
android:id="@+id/title_and_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/title_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fucking amazing video!!!!"
android:textColor="#000"
android:textSize="18sp" />
<TextView
android:id="@+id/desc_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title_txt"
android:layout_marginTop="8dp"
android:maxLines="4"
android:text="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." />
</RelativeLayout>
此时的 Activity 几乎都被注释掉了,因为我无法弄清楚这件事,所以我怀疑它与它有什么关系
可能有冲突?依赖关系
{
compile fileTree(dir: 'libs', include: ['*.jar'])
// androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
// exclude group: 'com.android.support', module: 'support-annotations'
// })
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.google.apis:google-api-services-youtube:v3-rev182-1.22.0'
compile 'com.google.http-client:google-http-client-android:1.20.0'
compile 'com.google.api-client:google-api-client-android:1.20.0'
compile 'com.google.api-client:google-api-client-gson:1.20.0'
}
最佳答案
尝试删除布局中 ImageButton 这一行中的“+”:
android:layout_below="@+id/imageView"
因为“+”应该只用在“android:id”参数上以将 id 分配给 View
有了这个额外的“+”layout_below 应该无法正确定位图像下方的按钮。
另一种可能性是尝试将所有“app:srcCompat”替换为“android:src”,因为您没有使用任何矢量绘图。
关于android - 消失的影像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43566108/