用2个RadioButton填充屏幕?

时间:2020-11-12 09:55:07

标签: java android-studio android-layout

如何用RadioGroup内部的两个radioButton填充ConstraintLayout?我找不到办法。我在这里发布了两张图片,一幅是我想要使其外观,另一幅是我现在的代码外观。

This is how it looks right now

This is how I want

function autoReply() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var answer = ss.getRange("A2").getValue();
  var fileattach = ss.getRange("B2").getValue();
  var mimetype = ss.getRange("C2").getValue();
  var interval = 1;
  var date = new Date();
  var day = date.getDay();
  var daysOff = [1,2,3,4,5,6,0];
  if (daysOff.indexOf(day) > -1){
    var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
    var threads = GmailApp.search('is:inbox after:' + timeFrom);
    for (var i = 0; i < threads.length; i++) {
      if (threads[i].isUnread()){
         var sender=threads[i].getMessages()[0].getFrom();
        if(PropertiesService.getScriptProperties().getKeys().length==0){
           PropertiesService.getScriptProperties().setProperty('from', '');
         }
        var scriptProperties = PropertiesService.getScriptProperties().getProperty('fromArray');
        var attach = DriveApp.getFilesByName(fileattach).next();
        if(scriptProperties.indexOf(sender)==-1){
          threads[i].reply(answer,{
          attachments:[attach.getAs(mimetype)]                
          });
          threads[i].markRead();
          scriptProperties=scriptProperties+sender; 
          PropertiesService.getScriptProperties().setProperty('from',  scriptProperties);
          }
      }
    }
  }

1 个答案:

答案 0 :(得分:1)

在阅读了StackOverflow的一些答案并尝试了许多事情之后,我能做的最好的事情就是做到这一点:

enter image description here

我采用了这种布局:

add_library( lib_a STATIC IMPORTED )
set_target_properties(lib_a PROPERTIES IMPORTED_LOCATION ${LIB_A_PATH})
target_link_libraries(${PROJECT_NAME} lib_a)

并使用此代码获取屏幕的高度并将其一半放到我的视图中,并显示在您的活动中:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MainActivity">

<RadioGroup
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:orientation="vertical"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <RadioButton
        android:id="@+id/radioButton"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:background="#193312"
        android:elevation="4dp"
        android:text="Paypal"
        android:textAlignment="center" />


    <RadioButton
        android:id="@+id/radioButton2"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="#122B33"
        android:elevation="4dp"
        android:gravity="center"
        android:text="Contrarreembolso"
        android:textAlignment="center" />
</RadioGroup>

</androidx.constraintlayout.widget.ConstraintLayout>

请注意,此布局的外观并不完美,您的单选按钮确实会在整个设备上展开,但高度不相等,如果要使按钮的高度相等,剩下要做的一件事就是计算操作栏高度并考虑在内。