该LayoutInflater.inflate文档是不看好的目的十分清楚我的attachToRoot参数.
attachToRoot:膨胀的层次结构是否应附加到根参数?如果为false,则root仅用于为XML中的根视图创建LayoutParams的正确子类.
有人可以更详细地解释,特别是根视图是什么,并且可能显示一个行为true和false值之间的变化的例子?
我正在写一些自定义视图,它们共享一些同名的属性.在他们各自的<declare-styleable>部分,attrs.xml我想对属性使用相同的名称:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyView1">
<attr name="myattr1" format="string" />
<attr name="myattr2" format="dimension" />
...
</declare-styleable>
<declare-styleable name="MyView2">
<attr name="myattr1" format="string" />
<attr name="myattr2" format="dimension" />
...
</declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud)
我收到一个错误,说明myattr1并且myattr2已经定义了.我发现我应该省略formatfor myattr1和myattr2in 的属性MyView2,但如果我这样做,我在控制台中获得以下错误:
[2010-12-13 23:53:11 - MyProject] ERROR: In <declare-styleable> MyView2, unable to find attribute
Run Code Online (Sandbox Code Playgroud)
有没有办法可以实现这一点,也许某种命名空间(只是猜测)?
android android-custom-view android-view android-custom-attributes
我有点困惑的角色forceLayout(),requestLayout()以及invalidate()该方法的View类.
他们何时被召唤?
我ViewPager用于刷卡之间Fragments,但我可以使用ViewPager在Views简单的XML布局之间滑动吗?
这是AdapterViewPager的页面,用于在片段之间滑动:
import java.util.List;
import com.app.name.fragments.TipsFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.view.ViewGroup;
public class PageAdapter extends FragmentPagerAdapter {
/**
*
*/
List<Fragment> fragments;
public PageAdapter(FragmentManager fm,List<Fragment> frags) {
super(fm);
fragments = frags;
}
@Override
public Fragment getItem(int arg0) {
// TODO Auto-generated method stub
return TipsFragment.newInstance(0, 0);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 4;
}
@Override
public void destroyItem(ViewGroup container, …Run Code Online (Sandbox Code Playgroud) 如何TextView在Android应用程序中添加和删除s 等视图,例如在原始股票Android联系人屏幕上按下字段右侧的小图标,然后添加或删除由a TextView和a组成的字段editTextView(来自我可以看到).
关于如何实现这个的任何例子?
我想知道这些州有什么不同.我没有找到任何网页澄清这一点.
我想围绕视图的角落,并在运行时根据内容更改视图的颜色.
TextView v = new TextView(context);
v.setText(tagsList.get(i));
if(i%2 == 0){
v.setBackgroundColor(Color.RED);
}else{
v.setBackgroundColor(Color.BLUE);
}
v.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
v.setPadding(twoDP, twoDP, twoDP, twoDP);
v.setBackgroundResource(R.drawable.tags_rounded_corners);
Run Code Online (Sandbox Code Playgroud)
我希望设置一个drawable,颜色会重叠,但他们没有.无论我执行第二个是生成的背景.
有没有办法以编程方式创建此视图,请记住,直到运行时才会确定背景颜色?
编辑:我现在只在红色和蓝色之间进行测试.之后,用户可以选择颜色.
编辑:
tags_rounded_corners.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners
android:bottomRightRadius="2dp"
android:bottomLeftRadius="2dp"
android:topLeftRadius="2dp"
android:topRightRadius="2dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud) android background rounded-corners android-layout android-view
开发时Android,您可以将目标(或最小)sdk设置为4(API 1.6)并添加android兼容包(v4)以添加支持Fragments.昨天我做了这个并成功实现Fragments了可视化来自自定义类的数据.
我的问题是:使用的好处是什么Fragments,而不是简单地从自定义对象获取View,并且仍然支持API 1.5?
例如,假设我有类Foo.java:
public class Foo extends Fragment {
/** Title of the Foo object*/
private String title;
/** A description of Foo */
private String message;
/** Create a new Foo
* @param title
* @param message */
public Foo(String title, String message) {
this.title = title;
this.message = message;
}//Foo
/** Retrieves the View to display (supports API 1.5. To use,
* remove 'extends Fragment' from the class …Run Code Online (Sandbox Code Playgroud) android software-design android-lifecycle android-fragments android-view
我的问题是:
有人请尝试向我解释原因
public void addView(View child) {
child.setDrawingCacheEnabled(true);
child.setWillNotCacheDrawing(false);
child.setWillNotDraw(false);
child.buildDrawingCache();
if(child.getDrawingCache() == null) { //TODO Make this work!
Log.w("View", "View child's drawing cache is null");
}
setImageBitmap(child.getDrawingCache()); //TODO MAKE THIS WORK!!!
}
Run Code Online (Sandbox Code Playgroud)
ALWAYS记录绘图缓存为空,并将位图设置为null?
在设置缓存之前,我是否必须实际绘制视图?
谢谢!