Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android以编程方式获取textView的重力值_Android - Fatal编程技术网

Android以编程方式获取textView的重力值

Android以编程方式获取textView的重力值,android,Android,我正在尝试获取Android中textView的当前重力值 我在stackoverflow上搜索了很多,但只找到了如何设置重力或如何获取边距、填充等内容的解决方案 那么,如何获得textView的当前重力呢 编辑:这只是getGravity()这是我的TextView: <TextView android:id="@+id/textView" android:gravity="center" android:text="Hello World!" andr

我正在尝试获取Android中textView的当前重力值

我在stackoverflow上搜索了很多,但只找到了如何设置重力或如何获取边距、填充等内容的解决方案

那么,如何获得textView的当前重力呢


编辑:这只是
getGravity()
这是我的
TextView

 <TextView
    android:id="@+id/textView"
    android:gravity="center"
    android:text="Hello World!"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

我已经有了
Toast
显示CENTER

方法
getGravity()
了吗?看我的答案@ZokerYes是getGravity,我不知怎么错过了:DIt发生了。。快乐编码:)当我设置重力开始时。使用getGravity从textview获得相同的结果时,它不会返回START。有什么想法吗??
textView = (TextView)findViewById(R.id.textView);

switch (textView.getGravity())
{
        case Gravity.CENTER:

            Toast.makeText(MainActivity.this, "CENTER"
                    , Toast.LENGTH_SHORT).show();

            break;

        case Gravity.TOP:

            Toast.makeText(MainActivity.this, "TOP"
                    , Toast.LENGTH_SHORT).show();

            break;

        case Gravity.BOTTOM:

            Toast.makeText(MainActivity.this, "BOTTOM"
                    , Toast.LENGTH_SHORT).show();

            break;

        case Gravity.CENTER_HORIZONTAL:

            Toast.makeText(MainActivity.this, "CENTER_HORIZONTAL"
                    , Toast.LENGTH_SHORT).show();

            break;

        case Gravity.CENTER_VERTICAL:

            Toast.makeText(MainActivity.this, "CENTER_VERTICAL"
                    , Toast.LENGTH_SHORT).show();

            break;
    }