android: layout_height 50% размера экрана

Я только что реализовал ListView внутри LinearLayout, но мне нужно определить высоту LinearLayout (она должна составлять 50% от высоты экрана) .

<LinearLayout
    android:id="@+id/widget34"
    android:layout_width="300px"
    android:layout_height="235px"
    android:orientation="vertical"
    android:layout_below="@+id/tv_scanning_for"
    android:layout_centerHorizontal="true">

    <ListView
        android:id="@+id/lv_events"
        android:textSize="18sp"         
        android:cacheColorHint="#00000000"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tv_scanning_for"
        android:layout_centerHorizontal="true">
    </ListView>

</LinearLayout>

Возможно ли это?

Я сделал нечто подобное для кнопки и EditText, но, похоже, не работает с макетами.

Это мой код:

    //capture the size of the devices screen
    Display display = getWindowManager().getDefaultDisplay();
    double width = display.getWidth();

    //my EditText will be smaller than full screen (80%)        
    double doubleSize = (width/5)*4;
    int editTextSize = (int) doubleSize;

    //define the EditText 
    userName = (EditText) this.findViewById(R.id.userName);
    password = (EditText) this.findViewById(R.id.password);

    //set the size
    userName.setWidth(editTextSize);
    password.setWidth(editTextSize);
45
задан Vadim Kotov 6 September 2019 в 07:57
поделиться