java - 带有 ImageView 的线性布局在膨胀后不会出现

标签 java android layout-inflater

我有一个线性布局,我想在 Activity 中显示它。这是我用来执行此操作的代码:

final LayoutInflater factory = getLayoutInflater();
final View ps = factory.inflate(R.layout.photo_shooting, null);
final RelativeLayout photoshooting = (RelativeLayout) ps;

//other code...

rscroll.addView(photoshooting, lp);

和布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/photoshooting"
android:background="@drawable/dropdownborder">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:id="@+id/selectedphoto" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/camera_and_film">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:id="@+id/camera"
        android:background="@mipmap/camera" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:id="@+id/cameraroll"
        android:background="@mipmap/cameraroll" />
</RelativeLayout>

问题是当我将其添加到相对布局rscroll时它没有出现。为什么我运行时看不到它?

最佳答案

这可能是因为您的relativelayout具有id“@+id/photoshooting”,但您正在将“R.layout.photo_shooting”添加到代码中。

关于java - 带有 ImageView 的线性布局在膨胀后不会出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35555814/

相关文章:

java - 如何使用 Itext 创建表格并将其添加到预定义的 pdf 模板?

android - Gradle 错误 : String index out of range: 0

android - 超时异常(从 Android 向 PHP 页面发送数据)

android - 是否有可用的无标记增强现实框架?

java - 如何通过在 Fragment 中单击按钮多次 inflatedView/容器?

java - 尝试使用堆栈查看预期输出

java - 如何让Swagger使用@ApplicationPath?

java - 使用Layout Inflater方法为动态创建的EditText创建TextView

Android LayoutInflater 问题

java - 在单例中进行正确的同步