我有一个如下的布局.现在,我不想将相对布局的宽度设置为固定240 dp.我想将相对布局的宽度设置为屏幕宽度的1/3.是否可以在xml文件中执行此操作.如果不可能,我怎么能用java代码实现呢?
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/fullscreen"
style="@style/translucent">
<RelativeLayout
android:layout_width="240dp"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:gravity="center"
android:background="#88000000"
android:id="@+id/sidebar">
</RelativeLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud) 如果有两个线程只读取全局变量,是否有必要使用互斥锁来锁定和解锁全局变量?
通常,我在解码视频时使用以下代码来获取当前帧号。
while(av_read_frame(pFormatCtx, &packet)>=0) {
if(packet.stream_index==videoStream) {
// Decode video frame
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
// Did we get a video frame?
if(frameFinished) {
int currentFrameNumber = pFrame->coded_picture_number;
}
/* Free the packet that was allocated by av_read_frame*/
av_free_packet(&packet);
}
Run Code Online (Sandbox Code Playgroud)
然后,当我实现查找功能时,我添加 av_seek_frame 来查找所需的位置,如下所示:
if(av_seek_frame(pFormatCtx, -1, seekTarget, 0 )<0){
LOG("log","error when seeking");
}
while(av_read_frame(pFormatCtx, &packet)>=0) {
if(packet.stream_index==videoStream) {
// Decode video frame
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
// Did we get a video frame?
if(frameFinished) {
int currentFrameNumber = pFrame->coded_picture_number;
}
/* Free …Run Code Online (Sandbox Code Playgroud) 在Rails中,我可以使用respond_to来定义控制器如何根据请求格式进行响应.
在routes.rb中
map.connect '/profile/:action.:format', :controller => "profile_controller"
Run Code Online (Sandbox Code Playgroud)
在profile_controller.rb中
def profile
@profile = ...
respond_to do |format|
format.html { }
format.json { }
end
end
Run Code Online (Sandbox Code Playgroud)
目前,在Django中,我必须使用两个URL和两个动作:一个返回html,一个返回json.
url.py:
urlpatterns = [
url(r'^profile_html', views.profile_html),
url(r'^profile_json', views.profile_json),
]
Run Code Online (Sandbox Code Playgroud)
view.py
def profile_html (request):
#some logic calculations
return render(request, 'profile.html', {'data': profile})
def profile_json(request):
#some logic calculations
serializer = ProfileSerializer(profile)
return Response(serializer.data)
Run Code Online (Sandbox Code Playgroud)
使用这种方法,逻辑代码变得重复.当然,我可以定义一个方法来进行逻辑计算,但代码直到详细.
在Django还有,我可以将它们组合在一起吗?
通常 wav 文件的 subchunk1size 是 16。但是,我有一些 subchunk1size = 18 的 wav 文件。我有 C++ 代码来读取 subchunk1size = 16 的 wav 文件。现在我想读取 subchunk1size = 18 的 wav 文件。任何帮助,将不胜感激。
typedef struct header_file
{
char chunk_id[4];
int chunk_size;
char format[4];
char subchunk1_id[4];
int subchunk1_size;
short int audio_format;
short int num_channels;
int sample_rate;
int byte_rate;
short int block_align;
short int bits_per_sample;
char subchunk2_id[4];
int subchunk2_size;
} header;
Run Code Online (Sandbox Code Playgroud)
上面是我的代码中的struct header_file,用于读取subchunk1size = 16的wav文件。