我在XML中遗漏了什么?

问题描述 投票:0回答:1

当我在1年前开发我的应用程序时,这个位置是正确的,但是现在,出现问题(裁剪)。

我不知道我错过了什么。我想我在XML中使用了正确的'weight'属性。

这是手机中的代码和结果。 (我的是Galaxy S6 Edge,Nougat)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">

<TextView
    android:id="@+id/txt_qna_content"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="10dp"
    android:layout_weight="0.7"
    android:text="Content"
    android:textColor="#000" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.3"
    android:layout_marginBottom="5dp">

    <TextView
        android:id="@+id/txt_qna_regdtm"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:paddingLeft="10dp"
        android:text="REG_DTM"
        android:textSize="10dp"
        android:textColor="#000" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:gravity="right"
        android:orientation="horizontal">

        <Button
            android:id="@+id/btn_qna_update"
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/icon_qna_update"
            android:onClick="onClick"
            android:visibility="visible" />

        <Button
            android:id="@+id/btn_qna_answer"
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/icon_qna_answer"
            android:onClick="onClick"
            android:visibility="visible" />

        <Button
            android:id="@+id/btn_qna_delete"
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/icon_qna_delete"
            android:onClick="onClick"
            android:visibility="visible" />
    </LinearLayout>
</RelativeLayout>
</LinearLayout>

而原始图片就是它!

android xml weight
1个回答
1
投票

试试这个:

        <Button
            android:id="@+id/btn_qna_update"
            android:layout_width="25dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:background="@drawable/icon_qna_update"
            android:onClick="onClick"
            android:visibility="visible" />

您似乎限制了按钮的高度,这就是图像被切割的原因。尝试使用wrap_content

© www.soinside.com 2019 - 2024. All rights reserved.