Android搜索栏文本宽度超出范围

Android搜索栏文本宽度超出范围,android,Android,这里我使用搜索栏和文本视图。当我更改搜索栏时,文本视图也会移动。当我到达搜索栏的最后一个位置时,文本视图超出范围 求你了,任何人都帮我一个忙 我在这里分享我的code。当我更改搜索栏时,我希望将文本视图与搜索栏位置一起移动 // Seek bar code seekbar_pay_restaurant_.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

这里我使用
搜索栏
文本视图
。当我更改
搜索栏
时,
文本视图
也会移动。当我到达
搜索栏的最后一个位置时,
文本视图
超出范围

求你了,任何人都帮我一个忙

我在这里分享我的
code
。当我更改
搜索栏
时,我希望将
文本视图
与搜索栏位置一起移动

    // Seek bar code         
    seekbar_pay_restaurant_.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    //change position of seekebar tool tip according to seekbar progress               
                    int x = seekBar.getThumb().getBounds().left;
                    Log.v("y value ",""+x);
                    int width = seekBar.getThumb().getMinimumWidth();
                    int textWidth=tv_tool_type_food_.getMeasuredWidth();
                    Log.v("textview Width","width"+textWidth);
                    Log.v("width",""+ width);
                    tv_tool_type_food_.setX(x);
                    if (seekbar_pay_restaurant_.getProgress() == 0) {
                        tv_tool_type_food_.setText(getResources().getString(R.string.hint_fast_food__));
                        // tv_tool_type_food_.setX(y);
                        return ;
                    } else if (progress == 1) {
                        tv_tool_type_food_.setX(x);
                        tv_tool_type_food_.setText(getResources().getString(R.string.hint_fast_casual__));
                        return ;
                    } else if (progress == 2) {
                      // tv_tool_type_food_.setX(x );
                        tv_tool_type_food_.setText(getResources().getString(R.string.hint_casual__));
                        return;
                    } else if (progress == 3) {
                          tv_tool_type_food_.setText(getResources().getString(R.string.hint_fine_dyning__));
                        return;
                    }
                    tv_tool_type_food_.setText(getResources().getString(R.string.hint_fast_food__));
                }
                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                }
            });
// seek bar xml file 
<SeekBar
                                android:id="@+id/seekbar_pay_restaurant"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:max="3"
                                android:progress="0"
                                android:thumbOffset="@dimen/two_dp"
                                android:layout_marginRight="@dimen/twenty_dp"
                                android:layout_marginLeft="@dimen/five_dp"
                                />
<TextView android:id="@+id/tv_tool_type_food"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                style="@style/label_white_h13"
                                android:background="@drawable/tooltip_bg"
                                android:typeface="normal"
                                android:text="@string/hint_fast_food__"
                                android:gravity="center"
                                android:paddingLeft="@dimen/seven_dp"
                                android:paddingRight="@dimen/seven_dp"
                                android:paddingTop="@dimen/ten_dp"
                                android:paddingBottom="@dimen/ten_dp"
                                android:layout_marginRight="@dimen/one_sp"
                                android:layout_marginLeft="@dimen/one_dp"/>
//搜索条形码
seekbar\u pay\u restaurant\uu.setonseekbarchaneglistener(新seekbar.onseekbarchaneglistener()){
@凌驾
public void onProgressChanged(SeekBar-SeekBar、int-progress、boolean-fromUser){
//根据seekbar进度更改seekebar刀尖的位置
int x=seekBar.getThumb().getBounds().left;
对数v(“y值”,“x+x”);
int width=seekBar.getThumb().getMinimumWidth();
int textWidth=tv_tool_type_food_.getMeasuredWidth();
Log.v(“文本视图宽度”、“宽度”+文本宽度);
对数v(“宽度”,“宽度+宽度”);
电视工具类型食品设置x(x);
if(seekbar\u pay\u restaurant\uu.getProgress()==0){
tv_tool_type_food_.setText(getResources().getString(R.string.hint_fast_food_));
//电视、工具、类型、食品、setX(y);
返回;
}否则如果(进度==1){
电视工具类型食品设置x(x);
tv_tool_type_food_.setText(getResources().getString(R.string.hint_fast_casual_));
返回;
}否则如果(进度==2){
//电视工具类型食品设置x(x);
tv_tool_type_food_.setText(getResources().getString(R.string.hint_casual_));
返回;
}否则如果(进度==3){
tv_tool_type_food_.setText(getResources().getString(R.string.hint_fine_dyning_));
返回;
}
tv_tool_type_food_.setText(getResources().getString(R.string.hint_fast_food_));
}
@凌驾
开始跟踪触摸时的公共无效(SeekBar SeekBar){
}
@凌驾
TopTrackingTouch(SeekBar SeekBar)上的公共无效{
}
});
//搜索条xml文件

希望这有帮助

如果要使用seekbar位置移动文本视图,则需要添加以下内容:

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();
int height = display.getHeight();

if (textview.getX() > width-textview.getLayoutParams().width) {
   textview.setX(width-textview.getLayoutParams().width);
}

这个“如果”可以防止出现这个问题。

试试这个
int x=seekBar.getThumb().getBounds().left-tv\u tool\u type\u food.getWidth感谢穆罕默德回复Hi Charan,根据您的代码,当搜索栏最后一个位置时,文本视图处于搜索栏第二个位置。是的,但没有正确切入。如果屏幕右侧或左侧有空间,请尝试在seekbar视图的左侧和右侧添加填充。若屏幕上并没有空间,那个么唯一的方法就是在文本视图超过max_x值时停止文本视图,或者在文本视图达到max_x值时减小文本视图的大小。
int seek_bar_width = seekbar.getMeasuredWidth();
int text_view_with = textview.getMeasuredWidth();
int max_x = seekbar.getX()+seek_bar_width-text_view_with;
Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();
int height = display.getHeight();

if (textview.getX() > width-textview.getLayoutParams().width) {
   textview.setX(width-textview.getLayoutParams().width);
}