Gulan查询UI排布

本文介绍如何在Android的相对布局中使两个元素在同一行且保持相同高度。通过实例展示使用layout_toRightOf和layout_alignBaseline属性来实现这一效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

遇到一个问题,如何在相对布局里把两个item放在同一行,而且高度一样呢?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

 <TextView android:id="@+id/keywordLabel"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="关键字:"
      android:paddingTop="15px" 
      />
    
 <EditText android:id="@+id/keywordEditText"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_toRightOf="@id/keywordLabel"
      android:layout_alignBaseline="@id/keywordLabel"
       />
    
<Button android:id="@+id/findKeywordButton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@id/keywordEditText"
      android:layout_alignRight="@id/keywordEditText"
      android:text="查找"
       />
    
 <TextView android:id="@+id/ChapterTextView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="章节查询"
      android:layout_below="@id/findKeywordButton"
      android:paddingTop="15px" />
    
 <TextView android:id="@+id/SuraIDText"
     android:text="章:"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@id/ChapterTextView"
      android:layout_alignBottom="@+id/SuraIDSpinner"
       />
    
 <Spinner android:id="@+id/SuraIDSpinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/SuraIDText"
        />
    
 <TextView android:id="@+id/AyaIDText"
     android:text="节:"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@id/SuraIDText"
      android:layout_weight="1.0"
      android:layout_centerInParent="true"
       />
 
 <Spinner android:id="@+id/AyaIDSpinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/AyaIDText"
        android:layout_alignBaseline="@+id/AyaIDText"
        android:layout_weight="1.0"
        />
</RelativeLayout>

  

最后一幅图的坐标轴和之前的不一致,帮我在最后一幅,倒数第二幅图生成横坐标,注意前面的横坐标需要一致 def onemergeimage_1(target_df,turbine_id,channellist,T=True,time_span = None,Savedir=None,angles=None): h = len(channellist) fig1, axs1 = plt.subplots(nrows=h+1, figsize=(4,h*2), dpi=100) parts = turbine_id.split('-') farm_name = parts[0]+'-'+parts[1] plt_df = target_df[farm_name][turbine_id] plt_df = plt_df.sort_values('plc_time',ascending=True) if time_span !=None: start_time = time_span[0] end_time = time_span[1] plt_df = plt_df[((pd.to_datetime(plt_df['plc_time'])>= pd.to_datetime(start_time))&(pd.to_datetime(plt_df['plc_time'])<= pd.to_datetime(end_time)))] else: plt_df = plt_df start_time = plt_df['plc_time'].iloc[0] end_time = plt_df['plc_time'].iloc[-1] time_datetime = pd.to_datetime(plt_df['plc_time'].values) # 定义通用绘图配置 plot_config = { 's' : 20, 'alpha': 0.5 } marker = ('.','x','*') color = [ '#648FFF', # 钴蓝 '#785EF0', # 紫罗兰 '#DC267F', # 洋红 '#FE6100', # 橙 '#FFB000', # 金 '#42B4CA', # 蓝绿 '#336633', # 墨绿 '#999999', # 中灰 '#000000' # 黑色 ] # 配置-------------------------------------------------------------------------- axs1[0].set_title(f'{turbine_id}:{start_time}-{end_time}', fontsize=8, pad=10) channel_number = 0 for i , channel in enumerate(channellist): if isinstance(channel, str): axs1[i].scatter( time_datetime, plt_df[channel], **plot_config, color=color[channel_number], marker = marker[0], label = channel ) axs1[i].legend(loc='upper right', fontsize=6) if channel == angles: axs1[i].set_yticks([-180, -100, -50, 0, 50, 100, 180]) axs1[i].set_yticklabels([-180, -100, -50, 0, 50, 100, 180]) axs1[i].set_ylim(-200, 200) else: for channel_sub in channel: axs1[i].scatter( time_datetime, plt_df[channel_sub], **plot_config, color=color[channel_number], marker = marker[0], label = channel_sub ) axs1[i].legend(loc='upper right', fontsize=6) if channel_sub == angles: axs1[i].set_yticks([-180, -100, -50, 0, 50, 100, 180]) axs1[i].set_yticklabels([-180, -100, -50, 0, 50, 100, 180]) axs1[i].set_ylim(-200, 200) channel_number = channel_number + 1 channel_number = channel_number + 1 # for row_idx in range(h): # ax = axs1[row_idx] # ax.grid(True, linestyle=':', alpha=0.5) # ax.tick_params(axis='both', which='major', labelsize=6) # ax.set_xlim(pd.to_datetime(start_time), pd.to_datetime(end_time)) # # if row_idx != len(axs1)-1: # # ax.set_xticklabels([]) # 2. 计算相对于起始时间的秒数 base_time = time_datetime[0] time_deltas = (time_datetime - base_time).total_seconds() # 4. 执行时频转换 freq_x, mag_x = non_uniform_fft(time_deltas, plt_df['PRE_NacAccel_X']) freq_y, mag_y = non_uniform_fft(time_deltas, plt_df['PRE_NacAccel_Y']) # 可视化 axs1[h].scatter(freq_x, mag_x, **plot_config, color=color[channel_number+1], marker = marker[0], label = freq_x) axs1[h].scatter(freq_x, mag_x, **plot_config, color=color[channel_number+2], marker = marker[0], label = freq_y) # 配置-------------------------------------------------------------------------- # ===== 统一样式配置 ===== # 优化时间轴显示 # plt.gcf().autofmt_xdate() # fig.suptitle(f'{turbine_id}',fontsize=12) plt.tight_layout() plt.gcf().autofmt_xdate() plt.tight_layout() if Savedir: plt.savefig(Savedir+'/'+turbine_id.replace('/','_')+'_'+start_time.replace('/','')+'.png') plt.show()
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值