这里我正在开发一个聊天演示应用程序。在我的条件是如何设置75%的屏幕布局?请找到附件图片Click here。 如何将绿色聊天区域减少到75%? 在这里我使用了recyclerview。 这是我的xml文件。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bgc1"
android:padding="5dp"
>
<TextView
android:id="@+id/textMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text Message"
android:layout_alignParentRight="true"
android:textColor="#FFF"
/>
</RelativeLayout>
</RelativeLayout>
答案 0 :(得分:0)
代码示例
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
app:layout_widthPercent="75%"
app:layout_heightPercent="50%"
/>
答案 1 :(得分:0)
您可以使用PercentRelativeLayout吗?您需要将其作为gradle
中的依赖项添加 compile 'com.android.support:percent:23.2.1'
然后你的布局看起来像这样
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<TextView
android:id="@+id/textMessage"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="end"
android:text="Text Message"
android:textColor="#FFF"
android:background="@drawable/bgc1"
app:layout_widthPercent="75%"
/>
</android.support.percent.PercentRelativeLayout>
</RelativeLayout>