繁体   English   中英

Android搜寻栏在FrameLayout中旋转时被切除/剪切

[英]Android seekbars cut off/clipped on rotation in FrameLayout

因此,我正在尝试制作一个穷人的交互式雷达图或蜘蛛图,但找不到。 我确实发现了这一点: Android版式视图旋转并间隔了一个圆? 并且想到了在其中旋转搜索杆的方法,虽然有点奏效,但是搜索杆本身被某些边界限制/切断,我不知道它是什么。 我尝试使用填充进行一些操作,但是它们没有帮助。

MainActivity代码如下所示:

protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Context context = getApplicationContext();

    final FrameLayout main = (FrameLayout)findViewById(R.id.main);

    int numViews = 6;
    for(int i = 0; i < numViews; i++)
    {
        // Create some quick TextViews that can be placed.
        TextView v = new TextView(this);
        SeekBar sb = new SeekBar(this);

        // Set a text and center it in each view.
        v.setText("View " + i);

        v.setGravity(Gravity.CENTER);
        v.setBackgroundColor(0xff00ffff);
        // Force the views to a nice size (150x100 px) that fits my display.
        // This should of course be done in a display size independent way.
        FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(400, 75);
        FrameLayout.LayoutParams lpv = new FrameLayout.LayoutParams(300, 75);

        // Place all views in the center of the layout. We'll transform them
        // away from there in the code below.
        lp.gravity = Gravity.CENTER;
        lpv.gravity = Gravity.CENTER;

        lp.bottomMargin = 150;
        lpv.bottomMargin = 150;

        // Set layout params on view.
        v.setLayoutParams(lpv);
        sb.setLayoutParams(lp);

        // Calculate the angle of the current view. Adjust by 90 degrees to
        // get View 0 at the top. We need the angle in degrees and radians.
        float angleDeg = i * 360.0f / numViews - 90.0f;
        float angleRad = (float)(angleDeg * Math.PI / 180.0f);
        // Calculate the position of the view, offset from center (300 px from
        // center). Again, this should be done in a display size independent way.
        v.setTranslationX(500 * (float)Math.cos(angleRad));
        v.setTranslationY(500 * (float)Math.sin(angleRad));

        sb.setTranslationX(250 * (float)Math.cos(angleRad));
        sb.setTranslationY(250 * (float)Math.sin(angleRad));
        // Set the rotation of the view.
        v.setRotation(angleDeg +90f);

        sb.setRotation(angleDeg );
        main.addView(sb);
        main.addView(v);
    }
}

而activity_main.xml代码是:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Settings"
android:layout_marginBottom="150px"/>
</FrameLayout>

任何水平(如果有8个)或垂直的搜索栏看起来都不错,但是对角线的搜索栏则无法正确显示。 结果是这样的: 旋转后剪切的搜寻条

因此,视图1和视图2几乎不会显示该条,尽管拇指都可以正确移动。 视图4和5根本不显示它。 我应该更改什么以使其完全可见? 非常感谢你!

编辑:添加numViews = 8和15的屏幕截图

奇怪的是,在右侧只看到一些对角线,在左侧看不到任何对角线。 是否也需要旋转某种填充“框”?

在此处输入图片说明

在此处输入图片说明

android设备的问题在于屏幕分辨率和密度不同。 因此,请阅读此“支持多屏”阅读此网站: https : //developer.android.com/guide/practices/screens_support.html

我最近也遇到了这个问题。 但是我正在使用Android Studio中的布局编辑器构建UI,并且想知道为什么旋转的搜索栏在预览中看起来不错。 所以我尝试添加一个软件layerType ,这似乎可行!

android:layerType="software"

或您的情况:

sb.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

希望这可以帮助。

屏幕截图

我在2个模拟器上运行了您的代码,看起来不错-

在此处输入图片说明 在此处输入图片说明

您正在运行什么Android版本?

您还需要在manifast xml文件中支持不同的屏幕。打开“ AndroidManifest”,并在android versionName之后添加以下内容。

<supports-screens android:smallScreens="true"

                android:normalScreens="true"

                android:largeScreens="true"

                android:xlargeScreens="true"

                android:anyDensity="true"

                android:resizeable="true"/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM