根据我的代码运行新的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
我试图在Android UI设计上从一组幻灯片中克隆一个活动的设计.但是我遇到一个非常简单的任务问题.
我创建了如图所示的布局,标题是TextViewa RelativeLayout.现在我想改变背景颜色RelativeLayout,但我似乎无法弄清楚如何.
我知道我可以在XML文件android:background中的RelativeLayout标签中设置属性,但是我将其设置为什么?我想定义一种可以在多个地方使用的新颜色.是一个drawable还是一个string?
另外我希望在Eclipse Android UI设计器中有一个非常简单的方法,我必须要丢失它?
我目前有点沮丧,因为这应该是一个活动,最多只需点击几下.所以任何帮助都非常感谢.:)

我正在测量文本Paint.getTextBounds(),因为我有兴趣获得要渲染的文本的高度和宽度.但是,实际呈现的文本总是比填充.width()的Rect信息宽一些getTextBounds().
令我惊讶的是,我进行了测试.measureText(),发现它返回了一个不同的(更高)值.我试一试,发现它是正确的.
为什么他们报告不同的宽度?我怎样才能正确获得高度和宽度?我的意思是,我可以使用.measureText(),但后来我不知道我是否应该相信.height()返回者getTextBounds().
根据要求,这里是重现问题的最小代码:
final String someText = "Hello. I believe I'm some text!";
Paint p = new Paint();
Rect bounds = new Rect();
for (float f = 10; f < 40; f += 1f) {
p.setTextSize(f);
p.getTextBounds(someText, 0, someText.length(), bounds);
Log.d("Test", String.format(
"Size %f, measureText %f, getTextBounds %d",
f,
p.measureText(someText),
bounds.width())
);
}
Run Code Online (Sandbox Code Playgroud)
输出显示的差异不仅得到大于1(且没有最后一分钟的舍入误差),也似乎增加与大小(我正要吸引更多的结论,但它可能是完全的字体相关的):
D/Test ( 607): Size 10.000000, measureText 135.000000, …Run Code Online (Sandbox Code Playgroud) 我在EditText我的布局中添加了一个,并添加了一个提示,并使其水平居中.
运行应用程序时,提示是不可见的.我发现我应该做ellipsize的TextView是start:
<EditText
android:id="@+id/number1EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="@string/hint1" />
Run Code Online (Sandbox Code Playgroud)
在Android文档中,我读到:
如果设置,则导致比视图宽的单词被
椭圆化而不是在中间断开.
问题是ellipsize在字典中找不到.任何人都可以向我解释一下我们可以通过ellipsize属性获得哪些好处?和之间有什么区别start,end,middle?
三星galaxy note 2 android版4.1.2
我知道之前已经提出过这个问题而且回复是不可能的
如何在android上的应用程序启动器图标上显示气球计数器
然而昨天我更新了facebook应用程序,它开始显示未读消息私人消息的计数器.为什么Facebook应用程序可以,我不能为我的应用程序这样做?


三星galaxy note 2 android版4.1.2
当我启动一个实现viewpager的活动时,viewpager创建了各种片段.我想为每个片段使用不同的布局,但问题是viewpager在最大值时只显示两个布局(在1之后的所有剩余片段上的第二个布局).
以下是实现viewpager的SwipeActivity的代码:
public class SwipeActivity extends FragmentActivity
{
MyPageAdapter pageAdapter;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_swipe);
pageAdapter = new MyPageAdapter(getSupportFragmentManager());
ViewPager pager=(ViewPager)findViewById(R.id.pager);
pager.setAdapter(pageAdapter);
ActionBar bar = getActionBar();
bar.setDisplayHomeAsUpEnabled(true);
}
/**
* Custom Page adapter
*/
private class MyPageAdapter extends FragmentPagerAdapter
{
public MyPageAdapter(FragmentManager fm)
{
super(fm);
}
@Override
public int getCount()
{
return 5;
}
@Override
public Fragment getItem(int position)
{
switch(position)
{
case 0: return new MyFragment();
case 1: return SecondFragment.newInstance("asdasd");
default : return RamFragment.newInstance("s"); …Run Code Online (Sandbox Code Playgroud) android android-layout android-fragments android-viewpager fragmentpageradapter
我有三个文件.XML,绘图函数和主Activity.LinearLayout我的XML文件中有一些.
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ef3"
android:id="@+id/img01"/>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#E8A2B4"
android:id="@+id/img02"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是绘图功能:
public class getBorder extends TextView {
public getBorder(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(android.graphics.Color.RED);
canvas.drawLine(0, 0, this.getWidth() - 1, 0, paint);
canvas.drawLine(0, 0, 0, this.getHeight() - 1, paint);
canvas.drawLine(this.getWidth() - 1, 0, this.getWidth() - 1,
this.getHeight() - 1, paint);
canvas.drawLine(0, this.getHeight() - 1, this.getWidth() - 1,
this.getHeight() …Run Code Online (Sandbox Code Playgroud) 我正在设计我的应用程序UI.我需要一个如下布局:

(<和>是按钮).问题是,我不知道如何确保TextView将填充剩余空间,两个按钮具有固定大小.
如果我在文本视图中使用fill_parent,则无法显示第二个按钮(>).
如何制作看起来像图像的布局?
是否可以在Android中设置视图的绝对位置?(我知道有一个AbsoluteLayout,但它被弃用了......)
例如,如果我有一个240x320px的屏幕,我怎么能添加一个ImageView20x20px,使其中心位于(100,100)?
我有一个DialogFragment包含RecyclerView(卡片列表).
其中RecyclerView一个或多个CardViews可以具有任何高度.
我想DialogFragment根据CardViews其中包含的内容给出正确的高度.
通常情况下,这将是简单的,我会成立wrap_content的RecyclerView这个样子.
<android.support.v7.widget.RecyclerView ...
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:scrollbars="vertical" >
</android.support.v7.widget.RecyclerView>
Run Code Online (Sandbox Code Playgroud)
因为我使用的RecyclerView这个不起作用,请看:
https://issuetracker.google.com/issues/37001674
和
在这两个页面上,人们建议扩展LinearLayoutManager和覆盖onMeasure()
我首先使用了第一个链接中提供的LayoutManager:
public static class WrappingLayoutManager extends LinearLayoutManager {
public WrappingLayoutManager(Context context) {
super(context);
}
private int[] mMeasuredDimension = new int[2];
@Override
public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state,
int widthSpec, int heightSpec) {
final int widthMode = View.MeasureSpec.getMode(widthSpec);
final …Run Code Online (Sandbox Code Playgroud) android android-layout android-fragments android-studio android-recyclerview