我正在开发一个med提醒应用程序 我有两个文本字段的线性布局,无法设置我的布局宽度和高度以匹配父调整到我的代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.nsk.medapp.MainActivity">
<LinearLayout
android:layout_width="368dp"
android:layout_height="495dp"
android:orientation="vertical">
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Add Pills"
android:textSize="50sp"
android:textAlignment="center"
android:layout_weight="1"/>
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Edit Pills"
android:textSize="50sp"
android:textAlignment="center"
android:layout_weight="1"/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:3)
您的问题是由ConstraintLayout引起的。如果您不需要它,只需删除并让LinearLayout成为父
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical">
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="0dp"
android:text="Add Pills"
android:textSize="50sp"
android:textAlignment="center"
android:layout_weight="1"/>
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Edit Pills"
android:textSize="50sp"
android:textAlignment="center"
android:layout_weight="1"/>
</LinearLayout>
答案 1 :(得分:0)
LinearLayout
而不是ConstraintLayout
LinearLayout
(您不需要它,因为外部线性布局可以做您想要的)LinearLayout
和TextView
的文字视图height
为0
,width
为match_parent
,因此可以根据屏幕进行调整< / LI>
答案 2 :(得分:0)
要充分利用layout_weight,请将height设置为0dp。此外,将两个文本视图都设置为高度match_parent会使事情变得混乱
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="0dp"
android:text="Add Pills"
android:textSize="50sp"
android:textAlignment="center"
android:layout_weight="1"/>
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="0dp"
android:text="Edit Pills"
android:textSize="50sp"
android:textAlignment="center"
android:layout_weight="1"/>
答案 3 :(得分:0)
似乎你在约束布局和带有权重属性的线性布局之间混乱。 同时我订了一些订单,请查看是否符合您的要求。我不 - 请更好地解释你的需求:
<?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="0dp">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:gravity="center"
android:text="Add Pills"
android:textAlignment="center"
android:textSize="50sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center"
android:text="Edit Pills"
android:textAlignment="center"
android:textSize="50sp" />
</LinearLayout>
答案 4 :(得分:0)
<td style="font-weight: bold;" class="auto-style10" headers="Sample Forms">
Sample Forms <br /><a
href="../../Skin/faq_help/help%20Library/PSM%20templates/Oilandnh3Log.xlxs"
target="_blank">Ammonia Loss and Oil Log</a> <br />
<a href="../../Skin/faq_help/help%20Library/PSM%20templates/Leak
Calculator.xls" target="_blank">Ammonia Loss Calculator<br />
<a href="../../Skin/faq_help/help%20Library/PSM%20templates/CONTRACTORS On-
Site Safety Review Form.docx" target="_blank">Contractor On-Site Safety
Review<br />