我创建了我的应用程序,其高度和宽度以像素为单位,用于分辨率为480x800的Pantech设备.
我需要转换G1设备的高度和宽度.我认为将其转换为dp将解决问题,并为两种设备提供相同的解决方案.
有没有简单的方法将像素转换为dp?有什么建议?
我想按原样加载值.我有两个dimension.xml文件,一个在/res/values/dimension.xml,另一个在/res/values-sw360dp/dimension.xml.
从源代码我想做的事情
getResources().getDimension(R.dimen.tutorial_cross_marginTop);
Run Code Online (Sandbox Code Playgroud)
这是有效的,但我获得的值乘以屏幕密度系数(hdpi为1.5,xhdpi为2.0等).
我也试过
getResources().getString(R.dimen.tutorial_cross_marginTop);
Run Code Online (Sandbox Code Playgroud)
这原则上可行,但我得到一个以"dip"结尾的字符串......
我已经设置了一个简单的ViewPager,每页都有一个高度为200dp的ImageView.
这是我的寻呼机:
pager = new ViewPager(this);
pager.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
pager.setBackgroundColor(Color.WHITE);
pager.setOnPageChangeListener(listener);
layout.addView(pager);
Run Code Online (Sandbox Code Playgroud)
尽管将高度设置为wrap_content,但即使imageview仅为200dp,寻呼机也会填充屏幕.我试图用"200"替换寻呼机的高度,但这给了我多种分辨率的不同结果.我无法将"dp"添加到该值.如何在寻呼机的布局中添加200dp?
如何使按钮上的可绘制更小?图标太大,实际上高于按钮.这是我正在使用的代码:
<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) 我正在构建一个UI,它在XML中都是静态定义的.所有这些都在整个地方都有重量,虽然它看起来正确,但我希望看到事情确实具有正确的高度和所有.问题是无论我在哪里调用.getHeight()我的格式布局都得到了0.我在onCreate()和onStart()中都尝试过.一样.也适用于所有UI对象.任何的想法?
package com.app.conekta;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.Toast;
public class Conekta extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public void onStart() {
super.onStart();
}
@Override
public void onResume() {
super.onResume();
FrameLayout fl1 = (FrameLayout) findViewById(R.id.headerFrameLayout);
FrameLayout fl2 = (FrameLayout) findViewById(R.id.footerFrameLayout);
Button b=(Button) findViewById(R.id.searchButton);
Log.d("CONEKTA", String.valueOf(b.getHeight()));
}
}
Run Code Online (Sandbox Code Playgroud)
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的应用程序中为一个简单的ImageView设置动画,我希望它从屏幕底部滑入并进入静止位置,其中视图的顶部50px离开屏幕顶部(例如最终位置)在X中,ImageView应该是-50px.我曾尝试使用AbsoluteLayout来做到这一点,但这实际上切断了ImageView的前50px,使得前50px永远不会被渲染.我需要让ImageView的前50px可见/渲染,同时它是动画,然后让它稍微离开屏幕.我希望我已经解释得那么好了.
这是我目前正在使用的布局和幻灯片动画(这当前不会渲染ImageView的前50px):
布局:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/QuickPlayClipLayout">
<ImageView android:id="@+id/Clip"
android:background="@drawable/clip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_y="-50dp">
</ImageView>
</AbsoluteLayout>
Run Code Online (Sandbox Code Playgroud)
动画:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="100%p"
android:toYDelta="0"
android:duration="1000"/>
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="1000" />
</set>
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我需要在当前TextSize的TextView在sp单位.
但是getTextSize()返回大小pixels.那有办法convert pixels to sp吗?
我在我的应用程序中实现了SwipeRefreshLayout.我需要更改必须向下滚动的高度来调用onRefresh()方法.我应该使用哪种方法来添加自定义高度?
SwipeRefreshLayout的实现
private SwipeRefreshLayout swipeLayout;
Run Code Online (Sandbox Code Playgroud)
在oncreate
swipeLayout = (SwipeRefreshLayout)view.findViewById(R.id.swipe_container);
swipeLayout.setOnRefreshListener(this);
swipeLayout.setColorScheme(android.R.color.holo_blue_dark,
android.R.color.holo_green_dark,
android.R.color.holo_purple,
android.R.color.holo_orange_dark);
swipeLayout.setSoundEffectsEnabled(true);
Run Code Online (Sandbox Code Playgroud)
在onrefresh方法中实现AsyncTask
@Override
public void onRefresh()
{
// Asynctask to perform some task
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试为android制作一个简单的绘图程序.
我有一个自定义View类来处理绘图.当我打电话了getWidth,并getHeightmetheds,我得到一个零.
但是,绘图工作正常,我在宽度和高度硬编码,所以它的工作原理.它为什么这样做?
我的View类
public class cDrawing extends View{
char BitMap[];
static final short WIDTH=160;
static final short HEIGHT=440;
static final char EMPTY=' ';
int mWidthSize;
int mHeightSize;
static final char RED ='R';
int y;
public cDrawing(Context context) {
super(context);
y=3;
// set up our bitmap
BitMap=new char[WIDTH*HEIGHT];
for(int i=0; i<WIDTH*HEIGHT; i++)
BitMap[i]=EMPTY;
// returns zero why???????
int h=getHeight();
h=400;
int w=getWidth();
w=320;
mWidthSize=w/WIDTH;
mHeightSize=h/HEIGHT;
// TODO Auto-generated constructor stub
}
Run Code Online (Sandbox Code Playgroud)
Activity类
public class …Run Code Online (Sandbox Code Playgroud) 在我的app小部件中,我有一个LinearLayout,其高度和宽度设置为fill_parent.有没有办法在运行时获取已分配给该视图的实际大小?