2016-03-17 107 views
0

这里我正在开发一个聊天演示应用程序。在我的情况是如何设置75%的屏幕布局?请找到附件图片Click here。 如何将绿色聊天区减少到75%? 在这里我使用recyclerview。 这是我的xml文件。如何将布局大小减少到屏幕的75%?

<?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

只需使用重量和重力。 – zgc7009

+0

你能解释一下我的编码吗? –

+0

你可以将你想要的视图命名为75%吗?从你的xml中不清楚你正在谈论哪个视图。 –

回答

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> 
+0

感谢兄弟。它正在工作 –

+0

不客气:) –

0

使用PercentRelativeLayout

代码示例

<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%" 
/> 

相关问题