Android 一个布局中的两半碎片一个接一个
这是我的.xml代码。 第一个片段是用于扫描条形码的扫描器片段。 第二个片段是内容片段,用于显示扫描条形码的结果和其中的提交按钮Android 一个布局中的两半碎片一个接一个,android,native,Android,Native,这是我的.xml代码。 第一个片段是用于扫描条形码的扫描器片段。 第二个片段是内容片段,用于显示扫描条形码的结果和其中的提交按钮 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="wrap_conte
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" >
<fragment android:name="me.dm7.barcodescanner.zxing.sample.SimpleScannerFragment"
android:id="@+id/scanner_fragment"
android:layout_width="match_parent"
android:layout_weight="0.5"
android:layout_height="300dp" />
<fragment
android:id="@+id/content_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
我想把内容片段放在扫描仪片段的正下方
我想在content\u片段中添加更多类似listview的视图。如何克服这一问题?
搞定了!
以下是变化
活动\u scan.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:layout_weight="1"
android:orientation="vertical"
android:layout_height="wrap_content">
<fragment android:name="com.example."
android:id="@+id/scanner_fragment"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="300dp" />
<fragment
android:id="@+id/content_fragment"
android:layout_width="match_parent"
android:layout_height="356dp"
android:layout_weight="1"
tools:layout="@layout/scan_result"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:layout_marginBottom="600dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill_horizontal">
<Button
android:id="@+id/reset"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_weight="1"
android:text="Reset" />
<Button
android:id="@+id/confirm"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Confirm" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
对于工具:layout=“@layout/scan\u result”
扫描结果.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:layout_weight="1"
android:orientation="vertical"
android:layout_height="wrap_content">
<fragment android:name="com.example."
android:id="@+id/scanner_fragment"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="300dp" />
<fragment
android:id="@+id/content_fragment"
android:layout_width="match_parent"
android:layout_height="356dp"
android:layout_weight="1"
tools:layout="@layout/scan_result"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:layout_marginBottom="600dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill_horizontal">
<Button
android:id="@+id/reset"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_weight="1"
android:text="Reset" />
<Button
android:id="@+id/confirm"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Confirm" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
-使用线性布局而不是相对布局 -对于线性布局,放置
android:weightSum=“2”
-每个框架布局都应该具有android:layout\u weight=“1”使用布局下方属性
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment android:name="me.dm7.barcodescanner.zxing.sample.SimpleScannerFragment"
android:id="@+id/scanner_fragment"
android:layout_width="match_parent"
android:layout_height="300dp" />
<fragment
android:id="@+id/content_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/scanner_fragment"
/>
</RelativeLayout>
使用线性布局,并将此属性赋予所有框架布局
android:layout_height="0dp"
android:layout_weight="1"
我希望这对你有帮助
多谢各位 我想要一个片段位于另一个片段之下,而这段代码给出的片段相邻于另一个片段,我不需要。我自己解决了这个问题,谢谢。请参阅上面的更改。我想要扫描程序片段下面的内容片段