Android 在找到ViewById后,LinearLayout变为RelativeLayout本身?信不信由你
在我的Android 在找到ViewById后,LinearLayout变为RelativeLayout本身?信不信由你,android,android-linearlayout,android-relativelayout,Android,Android Linearlayout,Android Relativelayout,在我的incident\u detail\u fragment.xml中,滚动视图中有一个LinearLayout。它的id是detail\u line\u布局。但是当我用findviewbyd方法从java调用它时,它不再是LinearLayout,而是RelativeLayout。有人能解释一下吗 此处incident\u detail\u fragment.xml <RelativeLayout xmlns:android="http://schemas.android.com/ap
incident\u detail\u fragment.xml
中,滚动视图中有一个LinearLayout
。它的id
是detail\u line\u布局
。但是当我用findviewbyd
方法从java调用它时,它不再是LinearLayout
,而是RelativeLayout
。有人能解释一下吗
此处incident\u detail\u fragment.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp">
<LinearLayout
android:id="@+id/headerLayout_incident_detial"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:paddingTop="5dp"
android:paddingBottom="5dp"
>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_below="@id/headerLayout_incident_detial"
android:layout_above="@+id/footer_incident_detail"
>
<LinearLayout
android:id="@+id/detail_line_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="10dp" >
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="@id/footer_incident_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:padding="5dp"
>
</RelativeLayout>
它变成了这样的RelativeLayout
。
另一件奇怪的事情是,我在调试模式下观看了滚动视图的子项。它仍然是线性布局
最尴尬的是,我比较了ScrollView的child和findViewByID的RelativeLayout的两个ID。它们不一样。
ScrollView的子ID->2131230886
RelativeLayout ID->2131230885此ID是否在任何其他布局文件中声明。但即使我这样做了,findViewById也只能在视图范围内工作。(view.findviewbyd())。@CristyYG您能否从资源名称中给出id<代码>int resId=getActivity().getResources().getIdentifier(“详细信息行布局”,“id”,getActivity().getPackageName())代码>剩余值与从findviewbyid获得的值相同?问题已解决。我什么也没做。只需清洁/构建并运行增益。它不再是相对的了此id是否在任何其他布局文件中声明。但即使我这样做了,findViewById也只能在视图范围内工作。(view.findviewbyd())。@CristyYG您能否从资源名称中给出id<代码>int resId=getActivity().getResources().getIdentifier(“详细信息行布局”,“id”,getActivity().getPackageName())代码>剩余值与从findviewbyid获得的值相同?问题已解决。我什么也没做。只需清洁/构建并运行增益。它不再是相对的了