Размещение ImageView над кнопками в центре

int widgetIDs[] = AppWidgetManager.getInstance(getApplication()).getAppWidgetIds(new ComponentName(getApplication(), WidgetProvider.class));

for (int id : widgetIDs)
    AppWidgetManager.getInstance(getApplication()).notifyAppWidgetViewDataChanged(id, R.id.widget_view);
}
0
задан Fantômas 4 March 2019 в 09:54
поделиться

4 ответа

В отличие от всех других ответов, я хочу объяснить вам, какой макет лучше всего использовать.

Для лучшего адаптивного макета рассмотрите возможность использования макета ограничений - очень прост в использовании. и удобно. Кроме того, когда вы используете LinearLayout с android:layout_weight, это как бы замедляет ваш макет - движку отображения макета требуется больше времени для отображения вашего макета, чем constraintLayout.

Пример использования макета ограничения:

    <androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="0dp"
        android:layout_height="324dp"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:src="@drawable/common_google_signin_btn_icon_dark"
        app:layout_constraintBottom_toTopOf="@+id/button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:text="Button"
        app:layout_constraintBottom_toBottomOf="@+id/button2"
        app:layout_constraintEnd_toStartOf="@+id/guideline2"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/button2" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:text="Button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@+id/guideline2"
        app:layout_constraintTop_toBottomOf="@+id/imageView" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.5" />


</androidx.constraintlayout.widget.ConstraintLayout>
0
ответ дан Tamir Abutbul 4 March 2019 в 09:54
поделиться

Замените ваш код следующим:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/back"
    tools:context="com.cash.nikito.Contact">

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

    <!-- add src attribute here -->
    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        android:layout_centerHorizontal="true" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView"
        android:orientation="horizontal"
        android:padding="20dp">

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button 1" />

        <Button
            android:id="@+id/buttonUpload"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Upload" />
    </LinearLayout>

</RelativeLayout>
0
ответ дан Vipul K. Patil 4 March 2019 в 09:54
поделиться

у вас есть много решений, и одно из них:

установите orientation = "vertical" для

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/toolbar"
    android:padding="20dp"> 

и после добавьте еще один LinearLayout с orientation = "Horizental" и внутри этой вставки две кнопки. [ 115]

0
ответ дан Afshin kh 4 March 2019 в 09:54
поделиться

попробуйте это

<LinearLayout 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"
android:orientation="vertical"
android:layout_below="@+id/toolbar">


<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" >


<ImageView
    android:layout_width="wrap_content"
    android:id="@+id/ivBack"
    android:src="@drawable/ic_launcher_background"
    android:layout_height="wrap_content" />



</android.support.v7.widget.Toolbar>


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_marginStart="20dp"
    android:layout_marginEnd="20dp"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="40dp"
        android:src="@mipmap/ic_launcher" />

    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="40dp"
        android:layout_height="wrap_content">


        <Button
            android:layout_width="0dp"
            android:id="@+id/bChoose"
            android:layout_weight="1"
            android:layout_height="wrap_content" />


        <Button
            android:layout_width="0dp"
            android:id="@+id/bUpload"
            android:layout_weight="1"
            android:layout_height="wrap_content" />


    </LinearLayout>


</RelativeLayout>


</LinearLayout>
0
ответ дан Sohel S9 4 March 2019 в 09:54
поделиться
Другие вопросы по тегам:

Похожие вопросы: