相关疑难解决方法(0)

在Android中替代AbsoluteLayout?

如果弃用AbsoluteLayout,我可以使用什么而不是它?

我已经完成了一个使用AbsoluteLayout的应用程序,但它不适用于不同的屏幕分辨率.我使用是因为我可以设置按钮的X和Y位置.我可以使用其他布局设置按钮的位置吗?

android

42
推荐指数
3
解决办法
5万
查看次数

Android翻译动画 - 使用AnimationListener将View永久移动到新位置

我有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);
Run Code Online (Sandbox Code Playgroud)

这是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" …
Run Code Online (Sandbox Code Playgroud)

android android-animation translate-animation

33
推荐指数
3
解决办法
10万
查看次数

TextView在某些分辨率下被削减

我有一个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 …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-xml android-recyclerview

16
推荐指数
1
解决办法
2277
查看次数

android中的自定义对象点击问题

我在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);
    }

}
Run Code Online (Sandbox Code Playgroud)

具有相似属性的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 …
Run Code Online (Sandbox Code Playgroud)

android click effect

6
推荐指数
1
解决办法
935
查看次数

Android:AbsoluteLayout?

我是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 …
Run Code Online (Sandbox Code Playgroud)

android android-layout

6
推荐指数
1
解决办法
5412
查看次数

GLSurfaceView 之上的 Android 视图同步

有没有一种好方法可以View在a之上绘制标准Android对象GLSurfaceView并同步两层之间的移动?

\n

我的布局看起来像

\n
<FrameLayout>\n     <RelativeLayout>\n     <MyCustomGLSurfaceView>\n</FrameLayout>\n
Run Code Online (Sandbox Code Playgroud)\n

MyCustomGLSurfaceView实现了一个摄像头,当用户适当地触摸屏幕时,该摄像头就会移动。

\n

在渲染器中的回调结束时,onDrawFrame()我调用回调来告诉RelativeLayout相机已移动,并且它应该根据需要更新任何子视图的位置。

\n

为了尝试同步两个层,我正在执行以下操作:

\n
    \n
  • 设定renderMode = RENDERMODE_WHEN_DIRTY范围内MyCustomGLSurfaceView
  • \n
  • MyCustomGLSurfaceView实现Choreographer.FrameCallback并在doFrame(frameTimeNanos: Long)方法调用中requestRender()
  • \n
  • onDrawFrame 调用回调来指示相机已移动,并RelativeLayout根据需要更新 it\xe2\x80\x99s 子视图的位置。
  • \n
  • 将相机的位置延迟 1 帧,因为MyCustomGLSurfaceView看起来 AndroidView对象直到下一帧才在屏幕上更新,而 则MyCustomGLSurfaceView立即更新。
  • \n
\n

其理论是,通过侦听Choreographer回调,渲染MyCustomGLSurfaceView会在应用程序重新绘制标准 UI 元素的同时进行。

\n

这似乎工作得相当好,但 Android 对象层中存在明显的卡顿View。另外,通过设置边距来定位 Android 层中的元素View会出现一些奇怪的行为(视图在离开屏幕时会被破坏,并且并不总是重新出现,有时甚至根本停止更新)。我尝试使用它们来定位它们translationX …

android opengl-es surfaceview glsurfaceview textureview

6
推荐指数
0
解决办法
217
查看次数

布局中按钮的确切位置

我想放置一些按钮 - 每个按钮在我知道的一个特定坐标处,并指定x和y位置.是否可以在特定坐标处放置按钮?如果有可能,这是正确的(Android编程方式)?

layout android button

5
推荐指数
1
解决办法
1万
查看次数

如何使用容器中顶部/左侧的百分比来定位视图?

我希望使用百分比在父视图中定位视图,类似于CSS中的绝对定位.在我的场景中,我将有一个变量和不可预测的视图数量将以这种方式定位.

下面是一个示例,它表示一个正方形内的3个TextView,其中包含以下位置:

1:前55%,左29%
2:前77%,左58%
3:前54%,左43%

有百分比头寸的观点

这是使用自定义绘图最好的完成吗?或者,在给定这些百分比的情况下,是否可以在特定类型的父视图中动态定位视图?如果是前者,我该如何处理文字?如果是后者,父母应该采用什么类型的观点,我应该如何设定这些百分比呢?

android position android-layout android-view

5
推荐指数
1
解决办法
951
查看次数

调整 imageView 的大小使它改变它的位置

我有一个相对布局,其中包含很少的图像,如下所示。

<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>
Run Code Online (Sandbox Code Playgroud)

在我的 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 …
Run Code Online (Sandbox Code Playgroud)

android android-layout

3
推荐指数
1
解决办法
2306
查看次数