我有一个线性布局,我想在 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/