我正在使用来自Chrisbanes Github的这个来源:https://github.com/chrisbanes/PhotoView并尝试使用LinearLayout创建ViewPager但是在将ViewPager转换为HackyViewPager时出现错误这是我的xml(bacaan.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"
android:orientation="vertical"
android:gravity="center_vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="7" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:orientation="horizontal" >
...
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在ViewPagerActivity.java上,我改变了这个:
mViewPager = new HackyViewPager(this);
setContentView(mViewPager);
mViewPager.setAdapter(new SamplePagerAdapter());
Run Code Online (Sandbox Code Playgroud)
对此:
setContentView(R.layout.bacaan);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
ViewPager mViewPager = (HackyViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(new AdapterGambarPager());
Run Code Online (Sandbox Code Playgroud)
我确实发现必须使用包名称声明自定义View,就像我发现的这个问题:在Android中创建自定义按钮类
所以我将xml ViewPager更改为我的包名,但仍然无效.任何线索?
编辑:这是日志
06-14 21:01:05.901: E/AndroidRuntime(28345): FATAL EXCEPTION: main
06-14 21:01:05.901: E/AndroidRuntime(28345): java.lang.RuntimeException: Unable to start activity ComponentInfo{uk.co.senab.photoview.sample/uk.co.senab.photoview.sample.ViewPagerActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class uk.co.senab.photoview.sample.HackyViewPager
06-14 …Run Code Online (Sandbox Code Playgroud) 我想创建一个非常简单的customView,上面有一些UIlabel,我该怎么办呢.任何教程或建议将不胜感激.我是新来的,之前没试过.
我用xib试过了.
@interface MyCustomView : UIView
@property (strong, nonatomic) IBOutlet UILabel *Label;
@end
Run Code Online (Sandbox Code Playgroud)
履行
#import "MyCustomTimer.h"
@implementation MyCustomView
-(id)initWithCoder:(NSCoder *)aDecoder{
if ((self = [super initWithCoder:aDecoder])){
[self addSubview:[[[NSBundle mainBundle] loadNibNamed:@"MyCustomView" owner:self options:nil] objectAtIndex:0]];
}
return self;
}
@end
Run Code Online (Sandbox Code Playgroud)
但我需要以编程方式进行,请帮忙.谢谢
我想创建一个类似于Google+应用通知的通知图标视图.不同之处在于我需要能够在运行时更改颜色,因为Google+图标为灰色或红色,所以我假设他们正在使用StateListDrawable.
对此最好的方法是什么?我更喜欢圆角的夹角,并且可以选择内部有一个可绘制的.此自定义视图也将放置在操作栏中.我仍然需要视图响应android:背景状态列表drawables所以我可以点击和选择按照工作.
此自定义视图也将放置在操作栏中.

如何在自定义视图中在画布顶部绘制按钮?(最好是在中间右侧)在做button.draw(画布)之前是否有必须调用的东西?
public class MyClass extends View {
public Simulation(Context context) {
super(context);
pauseButton.setText("TestButton");
pauseButton.setClickable(true);
pauseButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.i(TAG, "Button Pressed!");
}
});
public onDraw(Canvas canvas) {
super.onDraw(canvas);
pauseButton.draw(canvas);
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的时间
我已经创建了一个自定义UIView,我想用initialize它的自定义参数UIStoryboard.基本上,我已经加了UIView的UIStoryboard,我已经改变了类来我的自定义UIView.
在我的自定义UIView类中,我正在使用它的initWithCoder方法,initialize但我想使用提供的NSCoder来获取一些配置参数UIStoryboard,这可能还是有另一种方法将参数从UIStoryboard我的自定义传递UIView?
谢谢!!
我想View在Android上创建自定义.我试图尽可能简单地创建它并创建了一个几乎为空的类MyView并在我LinearLayout的应用程序中使用它,但是应用程序在"强制关闭"开始时失败.我怎样才能做一个简单的定制View?根据构建自定义组件,View如果我不覆盖,则获取大小100x100 onMeasure().
public class MyView extends View {
public MyView(Context context) {
super(context);
}
}
Run Code Online (Sandbox Code Playgroud)
我用它来LinearLayout:
<view
class="com.example.MyView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0" />
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
如果我使用itemon建议的构造函数和对超类的相应调用.然后"强制关闭"消失,但我LinearLayout的破坏,后面的组件MyView没有显示.
这是我的main.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"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0"
android:background="#f00"
android:text="Hello"
/>
<view
class="com.example.MyView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0"
android:background="#00f"
android:text="World"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用Android制作基于旧学校战舰棋盘游戏的游戏.我现在只是在试图感受它以及我可能需要制作游戏的组件.
基本上我目前在布局xml文件中的内容如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<org.greene.battleship.BoardView
android:id="@+id/board_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.greene.battleship.ShipView
android:id="@+id/ships_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我希望BoardView只占用屏幕的某个部分,即视图应该是我想在此视图中创建的内容的大小.在这种情况下,它是2D板.这是通过从扩展View覆盖onMeasure()方法来完成的.视图的宽度保持不变,但高度与宽度相同,给出了完美的正方形.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
int parent_width = MeasureSpec.getSize(widthMeasureSpec);
this.setMeasuredDimension(parent_width, parent_width);
Log.d("BOARD_VIEW", "BoardView.onMeasure : width = " + this.getMeasuredWidth() + ", height = "
+ this.getMeasuredHeight());
}
Run Code Online (Sandbox Code Playgroud)
我通过覆盖onSizeChanged()函数的视图并检查那里的值来检查视图维度是否已更改.
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh){
Log.d("BOARD_VIEW", "BoardView.onSizeChanged : width = " + w + ", height …Run Code Online (Sandbox Code Playgroud) 我有一个类似的课程,其中大约有10个
public class DataItemPlainView extends View{
public DataItemPlainView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}}
Run Code Online (Sandbox Code Playgroud)
现在我需要将TextView,ImageView等放在这个视图中.当我从某个地方调用它时,我想获取我的customView.将视图设置为自定义布局也是一种情况.
谢谢
是否可以在MBProgressHUD覆盖中加载自定义视图,有一个带MBProgressHUD类的自定义视图选项,但我可以使用customView分配XIB视图等吗?
我的Android项目中有一些自定义视图,我已将相关详细信息添加到attrs.xml文件中.现在我可以通过XML实现我的对象了.这很好用.
如何设置这些元素的样式?当我尝试在styles.xml中使用我的自定义属性时,会收到错误"找不到与给定名称匹配的资源:"
为了在普通的xml开发中使用自定义视图,我使用xmlns:app ="http://schemas.android.com/apk/res/bla.bla.bla".样式中使用的正确方法是什么?
这就是我目前的风格
<style name="Journey_DaySelect_Sunday">
<item name="app:onImage">@drawable/day_sunday_selected</item>
<item name="app:offImage">@drawable/day_sunday</item>
</style>
Run Code Online (Sandbox Code Playgroud) custom-view ×10
android ×7
ios ×2
uiview ×2
button ×1
canvas ×1
dimensions ×1
ios6 ×1
iphone ×1
objective-c ×1
parent-child ×1
storyboard ×1
view ×1
xib ×1
xml ×1