relativeLayout是动态创建的,我使用的是.scrollBy(),屏幕外的视图无法看到或点击

发布于 2024-10-13 10:08:16 字数 3759 浏览 4 评论 0原文

我在relativelayout上使用scrollBy()来尝试滚动到可见屏幕右侧的按钮,但我只看到空白屏幕。 屏幕边框上的按钮会被剪裁,并且在滚动(向任何方向)后仍保持剪裁状态。

我已经在相对布局参数上尝试了几乎所有 WRAP CONTENT 和 FILL PARENT 的组合。

我还尝试在 setContentview() 中使用 LinearLayout,但没有成功。

我需要视图水平滚动,并且应用程序设置为始终处于横向模式。

是否必须以某种方式重新绘制或刷新布局才能显示丢失的按钮?

我是否需要使用其他视图类型来实现这种功能?

感谢您的任何意见。

-nathan

这是从 onCreate() 的顶部到结尾的所有代码:

package golfcaddy.tools;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class GolfScoreRel extends Activity implements OnClickListener {

    // Settings file, preferences

    public static final String PREFS_NAME = "golfscore";
    public static final String PREFS_SCORES = "scores";
    public static final String PREFS_BACKGROUND_IMAGE = "backimage";

    SharedPreferences mSettings;

    private int currentX = 0;
    private int currentY = 0;

    int numHoles = 0;
    int numplayers = 0;

      RelativeLayout r1;

      LinearLayout lin;

      public int mLastScoreEntered;

      //manages unique ID's for all view inside Relative layouts
      int viewCount = 1;

     // int holeScoresFront[] = new int[9];
     // int holeScoresFrontb[] = new int[9];
      Button mLastClicked;


      Button exitButton;
      TextView pTotal1;
      TextView pTotal2;


    @Override
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



       // lin = new LinearLayout(this);
       // lin.setOrientation(LinearLayout.VERTICAL);

        /*    not used yet....
        GolfPlayer p1 = new GolfPlayer("P 1");
        GolfPlayer p2 = new GolfPlayer("P 2");
        GolfPlayer p3 = new GolfPlayer("P 3");
        GolfPlayer p4 = new GolfPlayer("P 4");
        */

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,  
                LayoutParams.WRAP_CONTENT);

        r1 = new RelativeLayout(this); // this layout will be set for contentview 

        r1.setLayoutParams(params);



        numplayers = 4;   //standard golf group
        numHoles = 18;  //standard golf round


        r1.addView(createCard(numplayers,numHoles));

        setContentView(r1);


    }  //end oncreate

这是我从某个地方借来的 r1.scrollBy() 代码:

Override 
public boolean onTouchEvent(MotionEvent event) {
  switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN: {
          currentX = (int) event.getRawX();
          currentY = (int) event.getRawY();
          break;
      }

      case MotionEvent.ACTION_MOVE: {
          int x2 = (int) event.getRawX();
          int y2 = (int) event.getRawY();

          r1.scrollBy(currentX - x2 , currentY - y2);
          currentX = x2;
          currentY = y2;
          break;
      }   
      case MotionEvent.ACTION_UP: {
          break;
      }
  }
    return true; 
}

屏幕截图注释:我们应该在右侧看到另外 8 个按钮。
最后一张照片显示了一张 5 人卡,其中 DEBUG 按钮被剪掉了。

哎呀,作为一个新用户,我不被允许发布图片。尝试在这里查看它们: http://groups.yahoo.com/group/nateandroiddev/photos/album/776905892/pic/list?mode=tn&order=ordinal&start=1&dir=asc

I am using scrollBy() on a RelativeLayout to try to scroll over to buttons to the right of the visible screen, but I only see blank screen.
Buttons on the screen border get clipped, and remain clipped after scrolling (in any direction).

I have tried nearly every combination of WRAP CONTENT and FILL PARENT on the relativelayout params.

I also tried using a LinearLayout in the setContentview(), it didn't work.

I need the view to scroll horizontally, and the app is set to be always in landscape mode.

Does the layout have to be redrawn or refreshed in some manner to enable the missing buttons to appear?

Do I need to use some other view type for this kind of functionality?

Thanks for any input.

-nathan

Here is all the code from top, to end of onCreate():

package golfcaddy.tools;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class GolfScoreRel extends Activity implements OnClickListener {

    // Settings file, preferences

    public static final String PREFS_NAME = "golfscore";
    public static final String PREFS_SCORES = "scores";
    public static final String PREFS_BACKGROUND_IMAGE = "backimage";

    SharedPreferences mSettings;

    private int currentX = 0;
    private int currentY = 0;

    int numHoles = 0;
    int numplayers = 0;

      RelativeLayout r1;

      LinearLayout lin;

      public int mLastScoreEntered;

      //manages unique ID's for all view inside Relative layouts
      int viewCount = 1;

     // int holeScoresFront[] = new int[9];
     // int holeScoresFrontb[] = new int[9];
      Button mLastClicked;


      Button exitButton;
      TextView pTotal1;
      TextView pTotal2;


    @Override
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



       // lin = new LinearLayout(this);
       // lin.setOrientation(LinearLayout.VERTICAL);

        /*    not used yet....
        GolfPlayer p1 = new GolfPlayer("P 1");
        GolfPlayer p2 = new GolfPlayer("P 2");
        GolfPlayer p3 = new GolfPlayer("P 3");
        GolfPlayer p4 = new GolfPlayer("P 4");
        */

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,  
                LayoutParams.WRAP_CONTENT);

        r1 = new RelativeLayout(this); // this layout will be set for contentview 

        r1.setLayoutParams(params);



        numplayers = 4;   //standard golf group
        numHoles = 18;  //standard golf round


        r1.addView(createCard(numplayers,numHoles));

        setContentView(r1);


    }  //end oncreate

here's my r1.scrollBy() code I borrowed from someplace:

Override 
public boolean onTouchEvent(MotionEvent event) {
  switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN: {
          currentX = (int) event.getRawX();
          currentY = (int) event.getRawY();
          break;
      }

      case MotionEvent.ACTION_MOVE: {
          int x2 = (int) event.getRawX();
          int y2 = (int) event.getRawY();

          r1.scrollBy(currentX - x2 , currentY - y2);
          currentX = x2;
          currentY = y2;
          break;
      }   
      case MotionEvent.ACTION_UP: {
          break;
      }
  }
    return true; 
}

Screen Shots notes: We should be seeing 8 more buttons to the right.
Last shot shows a 5 player card with DEBUG button clipped.

Dang,as a new user, I'm not allowed to post images. try viewing them here: http://groups.yahoo.com/group/nateandroiddev/photos/album/776905892/pic/list?mode=tn&order=ordinal&start=1&dir=asc

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧人九事 2024-10-20 10:08:16

由于我没有所有代码,因此需要尝试一些事情:

  1. 尝试将 postInvalidate() 添加到 ACTION_MOVE 案例的末尾。这将导致屏幕重绘。

  2. 您可能想在 onTouchEvent 方法中添加对 super() 的调用。

如果这些没有帮助,您的情况的屏幕截图将有助于澄清正在发生的情况。听起来滚动屏幕后并没有失效,因此您正在滚动相对布局的旧绘图,而不会导致它被重绘。

A couple of things to try since I don't have all the code:

  1. Try adding a postInvalidate() to the end of your ACTION_MOVE case. This will cause the screen to get redrawn.

  2. You probably want to add a call to super() in your onTouchEvent method.

If these don't help, a screen shot of your situation would help to clarify what is happening. It sounds like after scrolling the screen is not being invalidated so you are scrolling an old drawing of the relative layout without causing it to get redrawn.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文