Java Android拉伸布局宽度:绝对宽度+;百分比
我有两个按钮,第一个按钮应该有100dp的宽度,第二个按钮应该是(父-100dp)的宽度 这有可能实现吗 我尝试了以下方法:Java Android拉伸布局宽度:绝对宽度+;百分比,java,android,xml,Java,Android,Xml,我有两个按钮,第一个按钮应该有100dp的宽度,第二个按钮应该是(父-100dp)的宽度 这有可能实现吗 我尝试了以下方法: <android.support.v7.widget.ButtonBarLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:layout_wi
<android.support.v7.widget.ButtonBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="100dp"
android:layout_height="wrap_content" />
<Button
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
</android.support.v7.widget.ButtonBarLayout>
尝试使用RelativeLayout作为父项:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button1"
android:layout_width="100dp"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/button1" />
</RelativeLayout>
尝试使用RelativeLayout作为父项:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button1"
android:layout_width="100dp"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/button1" />
</RelativeLayout>
是否需要将android.support.v7.widget.ButtonBarLayout用作父级?使用RelativeLayoutButtonBarLayout扩展LinearLayout很容易实现,对吗?将ButtonBarLayout的权重和设置为1,将第二个按钮的布局宽度设置为0dp应该可以工作。是否需要将android.support.v7.widget.ButtonBarLayout用作父级?使用RelativeLayoutButtonBarLayout扩展LinearLayout很容易实现,对吗?将ButtonBarLayout的权重和设置为1,将第二个按钮的布局宽度设置为0dp应该可以工作。