gpt4 book ai didi

android:方向改变自定义 View , View 不改变

转载 作者:行者123 更新时间:2023-11-30 00:29:11 25 4
gpt4 key购买 nike

我的 Activity 中有一个自定义 View 元素和 2 个 xml 设计。 1 个用于横向模式,1 个用于水平模式,但是当应用程序的方向更改时, Activity 更改为横向 xml,但自定义 View 保持其水平设计。有人能帮我吗?。我必须实现自己的方式来更改配置更改或其他布局的布局吗?

public class NavigationDashBoard extends LinearLayout implements
ITurnByTurnContract.DashboardView,
TextToSpeechUtils.ITextToSpeechDelegate,
IRouteContract.ViewNavigationPresenter,
SVGPresenter.svgLoadDelegate{


public NavigationDashBoard(Context context) {
super(context);
init(context,null);
}

public NavigationDashBoard(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
init(context, attributeSet);
}


public NavigationDashBoard(Context context, AttributeSet attributeSet, @AttrRes int defStyleAttr){
super(context,attributeSet,defStyleAttr);
init(context,attributeSet);
}

private void init(Context context, AttributeSet attributeSet){
TypedArray a = context.obtainStyledAttributes(attributeSet, R.styleable.NavigationDashboardStyle);

mVoiceEnabled = a.getBoolean(R.styleable.NavigationDashboardStyle_navigation_voice,DEFAULT_VOICE);
mSpeedEnabled = a.getBoolean(R.styleable.NavigationDashboardStyle_navigation_show_speed, DEFAULT_SPEED);
a.recycle();
onCreate();
}

private void onCreate(){
View v = LayoutInflater.from(getContext()).inflate(R.layout.route_navigation_dashboard_tool, this, true);

mSmallFrame = (LinearLayout) v.findViewById(R.id.small_route_icon_frame);
mSmallPoiIcon = (AppCompatImageView) v.findViewById(R.id.route_navigation_dashboard_route_poi_small);
mSmallDirectionJunction = (TextView) v.findViewById(R.id.route_navigation_dashboard_route_junction_small);
mSmallDirectionsIcon = (AppCompatImageView) v.findViewById(R.id.route_navigation_dashboard_route_direction_small);

mdirections = (TextView) v.findViewById(R.id.route_navigation_dashboard_route_message);
mdirections.setOnClickListener(new SpeakRepeatListener());
mDirectionsIcon = (AppCompatImageView) v.findViewById(R.id.route_navigation_dashboard_route_direction);
mDirectionJunction = (TextView) v.findViewById(R.id.route_navigation_dashboard_route_junction);
mPoiIcon = (AppCompatImageView) v.findViewById(R.id.route_navigation_dashboard_route_poi);

mAudio = (ImageView) v.findViewById(R.id.route_navigation_dashboard_volume);
mAudio.setOnClickListener(new OnMute());

mSvg = new SVGPresenter();

}

最佳答案

我发现了我的问题,我不得不重写 onConfigurationChanged

@Override
protected void onConfigurationChanged(Configuration newConfig) {
removeAllViews();
onCreate();
}

关于android:方向改变自定义 View , View 不改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44775612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com