簡體   English   中英

如何從布局調整可繪制對象的大小

[英]How to resize a drawable from the layout

我正在嘗試自定義對話框的布局。 我想在對話框的左上角和右邊有一個徽標。 我寫了下面的布局,但是eclipse中的編輯器給我下面的布局,我不知道為什么徽標這么寬? 標題應該在它的右邊。 請讓我知道我在做什么錯?

布局

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

<TableLayout
    android:id="@+id/tl_MainTable"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical">

    <TableRow 
        android:id="@+id/tr_Logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/iv_Logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_launcher"/>
    </TableRow>
    <TableRow 
        android:id="@+id/tr_Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true">
        <TextView 
            android:id="@+id/tv_Title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Discovering Neigbouring Devices"
            android:/>
    </TableRow>

</TableLayout>

在此處輸入圖片說明

首先使用android:src代替android:background

所以最后您的ImageView

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView"
    android:src="@android:drawable/sym_def_app_icon"
    android:layout_weight="1"
    android:adjustViewBounds="true"/>

僅供參考 :使用線性布局代替表格布局

您擁有如此廣泛的徽標,因為您使用了TableRow

嘗試為ImageView添加android:layout_weight="1"

您需要使用RelativeLayout或LinearLayouts。 TableLayout對此不利。

這是一個例子:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">


<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:background="@color/material_deep_teal_500">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@android:drawable/sym_def_app_icon"
        android:layout_weight="1" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="LOGONAME"
        android:id="@+id/textView"
        android:layout_weight="8"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/abc_action_bar_overflow_padding_end_material" />
</LinearLayout>

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM