如果弃用AbsoluteLayout,我可以使用什么而不是它?
我已经完成了一个使用AbsoluteLayout的应用程序,但它不适用于不同的屏幕分辨率.我使用是因为我可以设置按钮的X和Y位置.我可以使用其他布局设置按钮的位置吗?
我有android翻译动画.我有一个随机生成位置的ImageView(next1,next2).我每隔3秒就调用一次虚空.它生成视图的新位置,然后制作动画并将视图移动到目标位置.翻译动画已实现AnimationListener.动画完成后,我将View永久移动到新位置(在OnAnimationEnd中).我的问题是动画位置与设置layoutParams位置不对应.当动画结束时,它会跳转到一个新位置,大约50-100像素.我认为位置应该是相同的,因为我在两种情况下都使用相同的值(next1,next2).请问您能找到找到溶剂的方法吗?
 FrameLayout.LayoutParams pozice_motyl = (FrameLayout.LayoutParams)  pozadi_motyl.getLayoutParams();    
            TranslateAnimation anim = new TranslateAnimation(Animation.ABSOLUTE,pozice_motyl.leftMargin, Animation.ABSOLUTE, next1, Animation.ABSOLUTE, pozice_motyl.topMargin, Animation.ABSOLUTE, next2);
            anim.setDuration(1000);
            anim.setFillAfter(true);
            anim.setFillEnabled(true);
            anim.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                }
                @Override
                public void onAnimationEnd(Animation animation) {
                    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(100, 100);
                    layoutParams.leftMargin = (int)(next1);
                    layoutParams.topMargin = (int)(next2);
                    pozadi_motyl.setLayoutParams(layoutParams);
                }
                @Override
                public void onAnimationRepeat(Animation animation) {
                }
            });
            pozadi_motyl.startAnimation(anim);
这是XML布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:id="@+id/pozadi0"
    android:gravity="center_vertical"
    android:layout_gravity="center_vertical"          
    android:background="@drawable/pozadi2"
    >
<LinearLayout
android:id="@+id/pozadi_motyl"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
  <ImageView android:id="@+id/obrazek_motyl"
             android:src="@drawable/motyl"
             android:layout_width="100dip" …我有一个RecyclerView包含CardViews TextView和a ImageView,以及其他一些布局的s .
问题是,在某些屏幕分辨率TextView下,它会被切断或推到下一行,这是我不想要的.
在其他决议中,TextView有足够的空间.  
如何组织布局,以便有足够的空间TextView,并相应ImageView地调整大小?  
这是我的RecyclerView项目的xml :
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
android:id="@+id/zmanCard"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
cardview:cardUseCompatPadding="false"
cardview:cardPreventCornerOverlap="false"
cardview:cardCornerRadius="4dp"
cardview:cardElevation="2dp">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?attr/colorPrimary"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:layout_gravity="top"
        android:gravity="center"
        android:orientation="vertical"
        android:background="?attr/colorPrimaryDark">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/zmanCardTitle"
            android:textColor="#ffffff"
            android:gravity="center"
            android:textSize="13sp" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <ImageView
            android:layout_width="24dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="4dp"
            android:alpha="0.8"
            android:id="@+id/zmanCardImage" />
        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="7dp"
            android:layout_marginLeft="0dp"
            android:layout_marginRight="4dp">
            <TextView …我在android中创建了一个自定义视图以在屏幕上显示球.现在我想要的是当我触摸那个球时它应该分成四个部分爆炸,每个部分应该向上,向下,向左,向右移动不同的四个方向.我知道我必须设置触摸侦听器以检测球上的触摸但是如何创建爆炸效果?这个问题现在解决了.我在屏幕上显示多个球,以便用户可以点击它并将其爆炸.
这是我的自定义视图:
public class BallView extends View {
    private float x;
    private float y;
    private final int r;
    public BallView(Context context, float x1, float y1, int r) {
        super(context);
        this.x = x1;
        this.y = y1;
        this.r = r;
    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawCircle(x, y, r, mPaint);
    }
}
具有相似属性的SmallBall除了一个是方向和一个爆炸方法在方向和动画标志上移动它以阻止它移动.
private final int direction;
private boolean anim;
public void explode() {
    // plus or minus x/y based on direction and stop animation if anim flag …我是Android新手.我喜欢在任何我想要的地方拥有自由范围的绘图对象.所以我一直在使用Absolute Layout.我收到一条消息,说要使用不同的布局.而且我已经读到这是因为不同手机的不同分辨率.我的问题是,这是不使用绝对布局的唯一原因吗?我制作了一个使用指标来调整像素的方法.
public int widthRatio(double ratioIn){
    DisplayMetrics dm = new DisplayMetrics(); //gets screen properties
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    double screenWidth = dm.widthPixels;      //gets screen height
    double ratio = screenWidth/100;           //gets the ratio in terms of %
    int displayWidth = (int)(ratio*ratioIn);  //multiplies ratio desired % of screen 
    return displayWidth;
}
//method to get height or Ypos that is a one size fits all
public int heightRatio(double ratioIn){
    DisplayMetrics dm = new DisplayMetrics(); //gets screen properties
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    double screenHeight = dm.heightPixels;    //gets screen height
    double …有没有一种好方法可以View在a之上绘制标准Android对象GLSurfaceView并同步两层之间的移动?
我的布局看起来像
\n<FrameLayout>\n     <RelativeLayout>\n     <MyCustomGLSurfaceView>\n</FrameLayout>\n它MyCustomGLSurfaceView实现了一个摄像头,当用户适当地触摸屏幕时,该摄像头就会移动。
在渲染器中的回调结束时,onDrawFrame()我调用回调来告诉RelativeLayout相机已移动,并且它应该根据需要更新任何子视图的位置。
为了尝试同步两个层,我正在执行以下操作:
\nrenderMode = RENDERMODE_WHEN_DIRTY范围内MyCustomGLSurfaceViewMyCustomGLSurfaceView实现Choreographer.FrameCallback并在doFrame(frameTimeNanos: Long)方法调用中requestRender()RelativeLayout根据需要更新 it\xe2\x80\x99s 子视图的位置。MyCustomGLSurfaceView看起来 AndroidView对象直到下一帧才在屏幕上更新,而 则MyCustomGLSurfaceView立即更新。其理论是,通过侦听Choreographer回调,渲染MyCustomGLSurfaceView会在应用程序重新绘制标准 UI 元素的同时进行。
这似乎工作得相当好,但 Android 对象层中存在明显的卡顿View。另外,通过设置边距来定位 Android 层中的元素View会出现一些奇怪的行为(视图在离开屏幕时会被破坏,并且并不总是重新出现,有时甚至根本停止更新)。我尝试使用它们来定位它们translationX …
我想放置一些按钮 - 每个按钮在我知道的一个特定坐标处,并指定x和y位置.是否可以在特定坐标处放置按钮?如果有可能,这是正确的(Android编程方式)?
我希望使用百分比在父视图中定位视图,类似于CSS中的绝对定位.在我的场景中,我将有一个变量和不可预测的视图数量将以这种方式定位.
下面是一个示例,它表示一个正方形内的3个TextView,其中包含以下位置:
1:前55%,左29%
2:前77%,左58%
3:前54%,左43%
这是使用自定义绘图最好的完成吗?或者,在给定这些百分比的情况下,是否可以在特定类型的父视图中动态定位视图?如果是前者,我该如何处理文字?如果是后者,父母应该采用什么类型的观点,我应该如何设定这些百分比呢?
我有一个相对布局,其中包含很少的图像,如下所示。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
    <ImageView
        android:id="@+id/image_2"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignLeft="@+id/increase"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="34dp"
        android:layout_marginTop="34dp"
        android:src="@drawable/ic_launcher" />
    <ImageView
        android:id="@+id/image_1"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignBottom="@+id/image_2"
        android:layout_marginBottom="14dp"
        android:layout_toRightOf="@+id/increase"
        android:src="@drawable/ic_launcher" />
    <ImageView
        android:id="@+id/image_8"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/ic_launcher" />
</RelativeLayout>
在我的 java 文件中,我需要执行一个小任务。当我单击图像时,它的大小应该增加。我试过了,它工作正常,这是我的代码
public class MainActivity extends Activity implements OnClickListener {
View imageView;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ImageView i1 = (ImageView ) findViewById(R.id.image_1);
    ImageView i2 = (ImageView ) findViewById(R.id.image_2);
             ImageView i3 = (ImageView ) findViewById(R.id.image_8);
            i1.setOnClickListener(this);
    i2.setOnClickListener(this);
    i3.setOnClickListener(this);
}
public void …android ×9
android-view ×1
android-xml ×1
button ×1
click ×1
effect ×1
layout ×1
opengl-es ×1
position ×1
surfaceview ×1
textureview ×1