在布局文件中,我有以下内容:
android:layout_width="100dp"
android:layout_height="wrap_content" android:layout_marginRight="10dp"
android:text="SYN"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="@drawable/rectanglepurple"
android:textColor="#000000"
android:gravity="right"/>
Run Code Online (Sandbox Code Playgroud)
我试图使用代码实现以下目标,到目前为止我有:
Resources res = getResources();
Drawable drawable1=res.getDrawable(R.drawable.rectanglepurple);
TextView idText = new TextView(getActivity());
idText.setText("SYN");
idText.setTextAppearance(getActivity(), android.R.style.TextAppearance_Medium);
idText.setTextColor(Color.BLACK);
idText.setGravity(Gravity.RIGHT);
idText.setBackgroundDrawable(drawable1);
Run Code Online (Sandbox Code Playgroud)
我不能锻炼如何处理
android:layout_width="100dp"
android:layout_height="wrap_content" android:layout_marginRight="10dp"
Run Code Online (Sandbox Code Playgroud)
任何帮助赞赏.
对于图标,它们是:36x36px 48x48px 72x72px 96x96px
对于屏幕尺寸,它们是:426x320 470x320 640x480 960x720
但我想我可能从网站上听说那些屏幕尺寸是dp.我知道"dp"是偶像素.但我的问题是:当我进入Adobe Illustrator创建小屏幕尺寸(426x320)的背景时,我应该使用PIXELS单元还是我需要将这些数字转换为其他数字.
我有这个布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/AppTheme.Widgets.Box"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="2dp"
android:scaleType="centerCrop"
android:background="#eee"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:gravity="center"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
所以,我正在从Web上将远程图像加载到ImageView中.我知道图像的尺寸,所以我知道宽度:高度比.现在,当我初始化我的布局时,我需要以某种方式应用这个比例,所以它在应用程序中不会像疯了一样跳跃.
只是一个简单的问题。在android中,绘制圆的代码Canvas如下。
canvas.drawCircle (float cx, float cy, float radius, Paint paint)
Run Code Online (Sandbox Code Playgroud)
我阅读了文档以了解这float radius是 dp 单位还是任何其他单位。没有这样的提及。
float radius那么,这里提到的单位是什么?是dp单位吗?
想知道如何在TextView.xml中调整xml中图像的大小LinearLayout。我阅读了一些使用setCompoundDrawablesWithIntrinsicBounds方法的解决方案,但无法正确解决。
这是图片:
我想减小徽标的大小。
这是我的TextView代码:
<TextView
android:id="@+id/heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/android_logo"
android:drawableStart="@drawable/android_logo"
android:gravity="top"
android:padding="16dp"
android:singleLine="true"
android:text="@string/heading"
android:textSize="20dp"
android:drawablePadding="5dp"/>
Run Code Online (Sandbox Code Playgroud) 我试图在我的应用程序中绘制一个矩形视图,但它在具有不同屏幕分辨率的不同设备中看起来不同.任何想法如何在所有不同的分辨率设计中绘制相同大小的视图.提前致谢.
我的Android应用程序在480x800像素分辨率下看起来很棒,但它在LDPI屏幕上突破240x400像素.我知道我可以在活动中获得屏幕的缩放因子,根据屏幕分辨率getResources().getDisplayMetrics().density可以给出确切的float值.
在我的应用程序,我已经使用RelativeLayout和ImageViewS中它,并设置使用图像的边缘setMargins(),这种方法是用像素在int其顶部,左侧,底部和正确的价值观,我怎么可以设置使用DPI因素我这些价值观?(这是一个浮动).我们有Math.floor()但是我使用像素将图像定位在非常特定的位置,并且方法返回的DPI因子在小数位上具有非常特定的值,这是不可忽略的,因此转换int对我来说不起作用.
更新
另外,我lp.setMargins(100,200,0,0);用来设置边距,我将使用DPI因子从设备中获得哪些修改?
PS我知道它更像是一个数学问题,而不是编程,但我对数学很差,对不起.
我有一个ImageView我想以编程方式设置的大小。所以我没有选择将不同大小的图像放在各自的drawable文件夹中。
基本上,我想LayoutParams根据屏幕分辨率进行设置,而不是执行我在下面所做的操作。如果设备是ldpi或mdpi,那么100,100...如果是hdpi,那么150,150等等。我怎样才能做到这一点?
ImageVIew imageView = new ImageView(this);
imageView.setLayoutParams(new ViewGroup.LayoutParams(100, 100));
layout.add(imageView);
Run Code Online (Sandbox Code Playgroud) 我正在尝试用Java创建一个简单的Android应用程序,但我在路上遇到了一个障碍.
我有一个包含许多位图的数组列表,我正在将它们绘制到画布上,但我正在使用像素的测量,这在大多数设备上都没有出现.
那么有没有办法找到我的图形在dp中的大小,并用dp将其缩放到屏幕密度/大小,并用dp或dip定位它.
我的图形(正方形):
图形尺寸ldpi = 50px
图形尺寸mdpi = 75px
hdpi中的图形大小= 100px
代码中的其他所有内容都很好,除了它看起来很奇怪?
任何帮助,将不胜感激.
詹姆士.
嗨我想在我的活动中更改图像视图的高度和宽度属性我按照以下方式尝试了它但它不适合我...
View card_view = getLayoutInflater().inflate(R.layout.card_details1,null);
coupon_img = (ImageView) card_view.findViewById(R.id.coupon_image);
// I tried this ////////
coupon_img.getLayoutParams().height = 20;
coupon_img.getLayoutParams().width = 20;
// I also tried this ////
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(100, 100);
coupon_img.setLayoutParams(layoutParams);
// also this one ////
coupon_img.setMaxHeight(10);
Run Code Online (Sandbox Code Playgroud)
但是我无法改变imageview src的高度和宽度.我有什么错误吗?这该怎么做?需要帮助......谢谢......
我有一个ImageView的XML:
<ImageView
android:id="@+id/iv"
android:layout_width="12dp"
android:layout_height="12dp"
android:src="@drawable/crossy"
android:scaleType="fitXY" />
Run Code Online (Sandbox Code Playgroud)
当我运行以下代码时:
iv = (ImageView) findViewById(R.id.iv);
Log.i("IV WxH", ""+iv.getWidth() + " " + iv.getHeight());
Run Code Online (Sandbox Code Playgroud)
LogCat 显示以下内容:
02-05 23:56:04.116: I/IV WxH(10211): 24 24
如何确保代码中的高度和宽度与XML中的高度和宽度保持一致?
如何在标签中获得这种外观?
描述我需要的样式的图像
我希望它:
•根据查看的页面更改文本的颜色(我已经通过默认的supportLibrary的Widget TabLayout实现了此功能)
•更改了背景笔触的颜色
•每个选项卡元素之间都有间距(无法通过padding选项实现)
我搜索了图书馆吗,但没有任何有用的细节,实际上,我不知道在搜索栏中键入什么内容。
这种风格的名称是什么?
提前致谢。
tabs android android-layout android-fragments android-studio
android ×12
imageview ×3
java ×3
canvas ×2
resolution ×2
textview ×2
android-view ×1
height ×1
layoutparams ×1
ondraw ×1
pixel ×1
pixels ×1
tabs ×1
xml ×1