我创建了我的应用程序,其高度和宽度以像素为单位,用于分辨率为480x800的Pantech设备.
我需要转换G1设备的高度和宽度.我认为将其转换为dp将解决问题,并为两种设备提供相同的解决方案.
有没有简单的方法将像素转换为dp?有什么建议?
根据我的代码运行新的Lint工具.它提出了很多好的建议,但这个我无法理解.
此标签及其子代可以替换为一个和复合drawable
问题:检查当前节点是否可以使用复合drawables替换为TextView.
包含ImageView和TextView的LinearLayout可以作为复合drawable更有效地处理
这是我的布局
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerInParent="true">
<ImageView
android:id="@+id/upImage"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:scaleType="centerInside"
android:src="@drawable/up_count_big">
</ImageView>
<TextView
android:id="@+id/LikeCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginBottom="1dp"
android:textColor="@color/gray"
android:textSize="16sp"
android:layout_gravity="center_vertical">
</TextView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,有人能提供一个如何制作复合可绘制的具体例子吗?
android textview android-layout android-linearlayout compound-drawables
如何使按钮上的可绘制更小?图标太大,实际上高于按钮.这是我正在使用的代码:
<Button
android:background="@drawable/red_button"
android:drawableLeft="@drawable/s_vit"
android:id="@+id/ButtonTest"
android:gravity="left|center_vertical"
android:text="S-SERIES CALCULATOR"
android:textColor="@android:color/white"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:drawablePadding="10dp">
</Button>
Run Code Online (Sandbox Code Playgroud)
鞋面是它应该看起来的样子,它现在看起来越低.

我尝试了这个,但没有显示图像.:-(
Resources res = getResources();
ScaleDrawable sd = new ScaleDrawable(res.getDrawable(R.drawable.s_vit), 0, 10f, 10f);
Button btn = (Button) findViewById(R.id.ButtonTest);
btn.setCompoundDrawables(sd.getDrawable(), null, null, null);
Run Code Online (Sandbox Code Playgroud) 我在4个按钮上添加了一些图标,它们在按钮旁边看起来很大.那么我该如何调整它们的大小呢?我在按钮上使用了drawableLeft来添加图标.
drawables被称为交易,奖杯,拼图和扩音器.图标太大了.content_main.xml文件:
<?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:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="tr.k12.evrim.evrimnews.MainActivity"
tools:showIn="@layout/activity_main">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/frameLayout"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Giri? Yap"
android:onClick="SignIn"
android:textStyle="bold"
style="@style/Widget.AppCompat.Button.Colored"/>
</LinearLayout>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_below="@id/frameLayout"
android:orientation="vertical">
<Button
android:text="Duyurular"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_below="@+id/frameLayout"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:id="@+id/button2"
android:drawableLeft="@drawable/megaphone" />
<Button
android:text="Kadromuz"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_below="@+id/button2"
android:layout_alignEnd="@+id/button2"
android:layout_marginTop="13dp"
android:id="@+id/button3"
android:drawableLeft="@drawable/puzzle"/>
<Button
android:text="Ba?ar?lar?m?z"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="12dp"
android:id="@+id/button5"
android:drawableLeft="@drawable/trophy"/>
<Button
android:text="Ortaklar?m?z"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="12dp"
android:id="@+id/button4" …Run Code Online (Sandbox Code Playgroud) 我看不到设置宽度的任何标签
在这里我设置textview高度,如果我设置宽度它将无法正常工作.
<TextView
android:id="@+id/nome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:drawableLeft="@drawable/ic_launcher"
android:height="50dp" />
Run Code Online (Sandbox Code Playgroud)
我怎样才能在xml中设置它?可能吗?